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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -