i`m working on a Greasmonkey Script, no i want to know how i can test a class for its content.
For example:
<div class="same">Some content</div>
<div class="same">Other content</div>
<div class="same">evenmorecontent</div>
<div class="same">yesthisisalsocontent</div>
<div class="same">youmaynotizedthat</div>
<div class="same">thecontentisdifferent</div>
<div class="same">the cake is yellow</div>
Now i create a array with this classes
var arr = document.getElementsByClassName('same');
Now i want to get the position of “evenmorecontent” in the Array! How do i do this?
If you wanted to use jQuery, you could do this in one line with the contains selector.
In straght JS you need to loop through the array:
If it occurs more than once, this will return the last position. It will return -1 if not found.