javascript - Get the id of <li> tag containing a specific value -


i have list as:

 <ul>  <li id="l1">1</li>  <li id="l2">2</li>  <li id="l3">hi</li>  </ul> 

by using jquery, got know if <li> contains value(say) hi. used:

if($('li:contains('hi')')){     alert('got value'); } 

now want know id of <li> in found value 'hi'. how id?

use this:

var id = $('li:contains("hi")').attr('id'); 

jsfiddle


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -