Data attribute value from first div using jQuery -
Data attribute value from first div using jQuery -
this should easy stuck! need info attribute first div in html chunk obtained using ajax. div can have other elements or text first item in html chunk. html not contain head, body or other start elements.
html looks below.
<div data-code="us"><span style="background-color:red">test</span><br /></div>
the jquery script looks below.
function loadcode(url) { $.get(url, function (data1) { var code = ""; //code = $(data1 + ":first").data("code"); // did not work //code = $(data1).data("code"); // did not work alert(code); }); }
this should work
$(data1).data('code');
jquery
Comments
Post a Comment