I wrote this script to have a method named “call” which acts as secretary to document.querySelectorAll(). Example:
var obj = {
call: function( s ) { return document.querySelectorAll( s ); }
};
obj.call(".test").innerHTML == "Changed";
<p class="test">Original</p>
So, obviously, (I would think) this would change the innerHTML value from “Original” to “Changed”, but is not working.
I have tried other tests such as .style.background = "red"; but that has not worked either.
I didn’t see any errors in Chrome’s error console so I can’t figure out why this isn’t working. I am a complete noob when it comes to javascript, so any help would be much appreciated.
QSA returns a NodeList (basically looks and acts like an array), docs here: https://developer.mozilla.org/en-US/docs/DOM/Document.querySelectorAll
As such, you would need to compare:
var isFoo = obj.call('.test')[0].innerHTML == 'foo';Some other points:
1) call is a reserved word in JS, better off picking something else
2) Are you trying to compare the result (what you’re currently doing) or are you trying to set the innerHTML? If it’s the latter, the code should read:
obj.call('.test')[0].innerHTML = 'foo';Because == is a comparison operator, not assignment.