The following code doesn't work! 'this' in in the context when i access it is the document.
$(document).ready(function(){
$(".myclass[id]").html(this.id);
});
How do I do the above without writing an extension or plugin? Is it possible?
The following code doesn't work! 'this' in in the context when i access it is the document.
$(document).ready(function(){
$(".myclass[id]").html(this.id);
});
How do I do the above without writing an extension or plugin? Is it possible?
$(".myclass[id]").each(function(){
//this is in the right context
});
You want to put an attribute value on the innerHTML each node on a set of matched elements.
I suggest you to iterate over all the matched elements, and get the attribute you desire of each one:
$(document).ready(function(){
$(".myclass[id]").each(function () {
$(this).html(this.id);
// or $(this).html($(this).attr('id'));
});
});