Reputation: 299
Suppose I want to get innerHTML
of below <li>
by its data-itemindex. i even don't know it is possible or not.
<li id="li:90" class="liGrid" data-itemindex="3" data-itemid="li:90" >
winoria</li>
i tried
alert($("li").find("[data-itemindex=3]").html());
alert($("li[data-itemindex='3']").text());
from How to select elements with jQuery that have a certain value in a data attribute array but doesnt help me.
Upvotes: 0
Views: 353
Reputation: 490
Try This:
var data = $('li').data('itemindex', 3).text();
alert(data);
Upvotes: 0
Reputation: 6620
Use the CSS tag selector to locate the matching element/s within the DOM:
$("[data-itemindex=3]")
You can even do some more advanced selectors using a similar syntax:
[title~=flower] /* Selects all elements with a title attribute containing the word "flower" */
[lang|=en] /* Selects all elements with a lang attribute value starting with "en" */
a[src$=".pdf"] /* Selects every <a> element whose src attribute value ends with ".pdf" */
a[src^="https"] /* Selects every <a> element whose src attribute value begins with "https" */
Upvotes: 1
Reputation: 82241
You can use:
$('li[data-itemindex="3"]').text();
or
$('li[data-itemindex="3"]').html()
Upvotes: 0