You need to provide a jQuery collection, not just a selector $.each():
$.each($("div[data-role=page]"), function (){
console.log(this.id);
});
Or even better:
$("div[data-role=page]").each(function (){
console.log(this.id);
});
Please note that I replaced $(this).attr('id')with this.id. It gets exactly the same property, but it is more efficient.
Script example
source
share