- Rep Power
Could someone explain to me what is happening here, step by step please?
I'm trying to learn by adapting available code
The only thing I partially understand is
Where the character string "Red Apple" is searched for in the page. And an if event is triggered if it is > -1? I don't under stand the > -1 part.
Last edited by Shawn; 06-09-2012 at 09:00 AM.
indexOf returns the index of the parameter in the instance string. If the parameter does not exist in the instance string, indexOf returns -1. The parameter in this case is 'Red Apple' and the instance string is document.body.innerHTML. So that if statement is checking if 'Red Apple' is found in document.body.innerHTML
Originally Posted by Shawn
This is fairly advanced code. This uses XPath (XML Path language) to find a certain element in the document. I believe '//b[. = "What What What Stick"]' finds a bold element (<b> that contains the text "What What What Stick".
This code looks to see if the previous XPath expression found the element (snapshotlength > 0). If so, it sets the first resultant element to item (for convenience purposes). It then sets a variable (selectedlink) to the item's previousSibling's previousSibling (I can't really explain this without seeing the HTML). It then points the browser to that URL.
This looks like code for a GM ABer or something like that. Hope I helped.
The Following User Says Thank You to Zachafer For This Useful Post:
- Rep Power
Yes I understand this now. Yes, it is from a GM ABer that I'm trying to adapt.