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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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+/); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.