I'm encountering a typical situation while accessing the innerHTML
property using jQuery
. I've fetched the target button using the jQuery attribute selector.
Below is the snippet of jQuery attribute selector.
jQuery('button[type="button"][class="btn btn-primary"]').each(function () {
var btn = jQuery(this);
console.log(btn);
if (btn[0].innerHTML === "OK") {
console.log("ok");
jQuery(this).click();
}
});
Following is the screenshot of the console log of the target button. It's innerHTML
property is set to OK
.
Following is the screenshot of the value of the innerHTML
while debugging the target button object. In this case the value is ""
.
Ideally, the values of the innerHTML
should be the same for both the cases.
EDIT Why does this behavior differ that the ideal one? For both of the cases, the value of the innerHTML should be the same.
Also, there were multiple buttons. I have taken screenshots of different buttons. Thus their ID's
are different. But still, the behavior is same.