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

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -