user2965583 user2965583 - 1 year ago 91
CSS Question

Change the text of links with an specific class, using javascript

I´m looking for a way to replace the text of all the links with an specific class, using javascript (not jquery). I´d like all the links with that specific class, to have a generic text such as: "click here".

Any help would be apreciated, thanks in advanced

Answer Source

I would use getElementsByClassName to acquire an array of the links. You can then loop through these elements making any changes required.

Heres a Fiddle that also includes some validation to only chenge the text of anchor tags in case you use targetClass for anything else in other elements.

EDIT: looks like other beat me to it :-) (also fixing type in function)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download