Dojo data attribute finding and Dojo equivalent to jQuery's $(this) -
hey trying value 1 of elements. data element called data-lang
, here example of it:
<p class="maintext" data-lang="es">welcome</p>
this dojo javascript:
dojo.query("[data-lang]").foreach( function(item){ var thetext = dojo.attr(item, "innerhtml"); } );
this doesn't seem work don't anything. looking above "es"
also, how dojo handle jquery equivalent of $(this)
?
the query above should work fine. sure you're waiting dom ready? if you're using amd, should use following:
require([ "dojo/query", "dojo/domready!" ], function(query) { // code });
or following non-amd:
dojo.addonload(function() { // code });
about second question, there no alternative. dojo/query
not pass current node scope of callback functions 1 you're using in foreach()
.
however, can current node parameter, can following:
dojo.query("[data-lang]").foreach(function(item) { query(item).attr("innerhtml"); });
but remember result array if use dojo/query
module.
here's full example: http://jsfiddle.net/5nguxm8f/
Comments
Post a Comment