javascript - Ask for multiple id's with the same data attribute -
i'm trying check data attribute in multiple list items.
my html:
<ul id="year"> <li id="2006">2006</li> <li id="2007">2007</li> <li id="2008">2008</li> <li id="2009">2009</li> <li id="2010">2010</li> <li id="2011">2011</li> <li id="2012">2012</li> <li id="2013">2013</li> <li id="2014">2014</li> </ul>
and jquery:
jquery('#year li').click(function() { var year = jquery(this).attr('id'); if ((jquery(this).data('state') === undefined) || (jquery(this).data('state') == "off")) { jquery(this).data('state', 'on'); } else { jquery(this).data('state', 'off'); } });
now trying check if there list items "state" == "on" this:
if ((jquery('#year li').data('state') == "on"))
but not seem working...
edit: tried different snippets gave me: none of them worked made simple loop looks in every list point itself:
( var y = 2006, l = 2015; y < l; y++ ) { if ((jquery('#year #'+y).data('state') == "on")) { alert('data found'); }
another problem didnt had event before code! support!
the jquery('#year li')
return array of jquery objects.
you need loop each
one
$('#year li').each(function () { if ((jquery(this).data('state') === "on")){ alert("on state found"); } });
Comments
Post a Comment