i is the index of the element, you want the element to use it, for example:
// The first argument is the index, the second is the element $('a').each(function(index, element) { if($(element).attr("href") == "mywebsite.co.uk") { $(element).html("It Worked!"); // Change this to .html() } console.log('Index is:'+index+', Element is'+element); }); <a href="mywebsite.co.uk"></a>
In addition, I changed .innerHtml() to .html("content in here") . To update the HTML inside the returned <a></a> (element) tag.
Check the JSFiddle . http://jsfiddle.net/2scug/1/
Anil
source share