javascript - jquery: onclick change background color -
i have following ul - li html.
<ul> <li><span id='select1'>text</span></li> <li><span id='select2'>text</span></li> <li><span id='select3'>text</span></li> <li><span id='select4'>text</span></li> <li><span id='select5'>text</span></li> <li><span id='select6'>text</span></li> </ul>
if click on specific <span>
, background color should changed. i.e. if click on span having id='select3'
, background-color should changed.
how can done using jquery?
try 1 :
$('li span[id^="select"]').click(function(){ $(this).css('background-color',"#ccc") })
what is, clicking span
inside li
having id starting 'select' changes backgound color.
Comments
Post a Comment