javascript - How to get an element by its data-itemindex? -


suppose want innerhtml of below <li> data-itemindex. don't know 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 select elements jquery have value in data attribute array doesnt me.

use css tag selector locate matching element/s within dom:

$("[data-itemindex=3]") 

you can more advanced selectors using similar syntax:

[title~=flower] /* selects elements title attribute containing word "flower" */ [lang|=en] /* selects elements lang attribute value starting "en" */ a[src$=".pdf"] /* selects every <a> element src attribute value ends ".pdf" */ a[src^="https"] /* selects every <a> element src attribute value begins "https" */ 

full documentation.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -