Fabis94 Posted June 30, 2010 Share Posted June 30, 2010 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 Link to comment https://forums.phpfreaks.com/topic/206280-changing-href-tags/ Share on other sites More sharing options...
XeNoMoRpH1030 Posted June 30, 2010 Share Posted June 30, 2010 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 More sharing options...
Fabis94 Posted June 30, 2010 Author Share Posted June 30, 2010 Ok and how do i get the number out of the get() function? Link to comment https://forums.phpfreaks.com/topic/206280-changing-href-tags/#findComment-1079160 Share on other sites More sharing options...
XeNoMoRpH1030 Posted June 30, 2010 Share Posted June 30, 2010 Oh, sorry. I skipped right over that. You can try something like: var id = posts.href.match(/\d+/); Link to comment https://forums.phpfreaks.com/topic/206280-changing-href-tags/#findComment-1079167 Share on other sites More sharing options...
Fabis94 Posted June 30, 2010 Author Share Posted June 30, 2010 Ok thanks a lot i finished my script Link to comment https://forums.phpfreaks.com/topic/206280-changing-href-tags/#findComment-1079170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.