JQuery's wildcard symbol to ignore characters in the middle? -
i'm wondering how search through of html li matching id attribute. google search, see begin , end nothing use both ignore middle part.
example...
to elements starting "jander" should use:
$("li[id^=jander]")
to end "jander"
$("[id$=jander]")
but matching ones start "abc" , end "xyz"?
$("li[id???=abc???xyz]")
as in
$("li[id???=abc???xyz]").on('click', function() { alert('foo'); });
you can chain expressions:
$('li[id ^="abc"][id $="xyz"]')
$('li[id ^="abc"][id $="xyz"]').each(function(){ $("ul#results").append('<li>' + $(this).text() + '</li>'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> unit tests: <ul> <li id="foo">a</li> <li id="bar">b</li> <li id="abc?????xyz">c</li> <li id="ab???xyz">d</li> <li id="abcxyz">e</li> </ul> results: <ul id="results"> </ul>
Comments
Post a Comment