fletchsod fletchsod - 14 days ago 5
jQuery Question

How to get the attribute's value from outerHTML's text?

How do I get the attribute's value from "data-column" in the outerHTML text?

$.each($groupingColumnUl[0].children, function(i1, o1) {
alert(o1.outerHTML.prop('data-column'); //.attr('data-column'); //.find('data-column');
});


The actual value inside the outerHTML is

<li class='ui-state-default' data-column='Model'><span style='display:inline-block;' class='ui-icon ui-icon-close'></span>Model</li>


I want to get the value "Model"

Answer

Try.

$.each($groupingColumnUl[0].children, function(i1, o1) {
   alert($(o1).data('column'));
});

or (if older JQuery version) :

$.each($groupingColumnUl[0].children, function(i1, o1) {
   alert($(o1).attr('data-column'));
});