Jump to content

Changing href tags


Fabis94

Recommended Posts

Ok so i'm trying to write a Greasemonkey script to change all the hrefs on a single page.

 

The href by default looks like this:

 

<a href="javascript:get('246154895')" class="postid">ID</a>

 

What i'm trying to do is make the number from get() appear in stead of "ID".

How should i get this done?

 

I started up with this:

 

var posts = document.getElementsByClassname('postid');

for (i=0; i<posts.length; i++) {
//Replacing
}

 

But i doubt it will work, since there are other items with the class "postid" that aren't related to these tags i'm trying to change.

 

P.S. I'm new to JS so yeah :P

Link to comment
https://forums.phpfreaks.com/topic/206280-changing-href-tags/
Share on other sites

It might be cumbersome, but you could always check the innerHTML within that loop and see if it equals ID.

 

If there are other unique tags around it, those might provide a more efficient way of grabbing the ones you want instead of all the postid's.

Link to comment
https://forums.phpfreaks.com/topic/206280-changing-href-tags/#findComment-1079159
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.