I have the following html code.
<ul>
<li data-details="li1">first</li>
<li >second</li>
</ul>
Notice that for the first element i have add data-details
attribute with a value.
For the 2nd li
element i'm adding the same using jquery. Here is my JavaScript code.
$(document).ready(function()
{
$("ul li:nth-child(2)").data("details","li2");
console.log($("ul li:nth-child(2)").data()); //data can be verified using this
alert($("ul li[data-details=li1]").length); //resulting in alert 1
alert($("ul li[data-details=li2]").length); //resulting in alert 0
});
The data is added we can verify by checking the console. However i'm not able to select the element based on value of data-details
which is being added by jquery. Why is it happening so ?
and Here is the jsfiddle link