H,i I need to edit some links on a page. The first part of below code works but causes other problems on the page because the id is not targeted. The second part of code works for text but not links. I can’t just replace the links as a query will be dynamically added to the end of each link. So in summary i just need to replace parts of all links with an input id “btnViewDetails”. Any help would be great. Cheers
Hi Ralph thanks for the quick response. Below is the current html and what i need to chagnge it to.
It’s difficult because I need to keep the"?VacancyId=2516" part dynamic. As you can see there are 2 parts that need to be changed : “Jobseekers” to “mobile” and “JobPositionDetail.aspx” to “JobPositionDetail_Mobile.aspx”. There will be multiple buttons on the page so I need to make sure they all change, but with VacancyId still being unique for each. thanks so much for your help.
This is probably just an annoying question, but I’d be interested to know why you are using inputs for what seem to be links. It looks like it would be better to update the HTML. If JS fails for any reason (and it can) then those buttons are dead, which is not a good situation.
Are you seeking this JS solution because there’s too much on the site to recode?
Hi, a very good question. I’m working with a sharepoint webpart. The functionally of the webpart is fine except I’m using the webpart in a different part of the site so i need it’s results to load onto another page. Obviously it would be better for me to recreate or edit the web part, but at this point I am unable to do that. Any ideas. thanks again.
Hi I’m not sure what you mean I just want to target everything with that id. I can’t use the class because that class is used on other parts of the page. Any thoughts.
What I mean is that on any given page only one element should have an id of “btnViewDetails”
If more than one element then they should have class “btnViewDetails”
If you have javascript get an id you can’t expect it to work as hoped if there are more than one element having the same id value. That is, the first thing you should do is correct the mark-up. i.e. validate it http://validator.w3.org/
Thanks, thats a good point, unfortunately I am working with an old sharepoint web part and thats the way the code is generated. The links are distinguished by the vacancyid. Is there anyway around this? I can’t change the class, I need to use the id. Cheers
An element can have more classes, so you don’t depend on existing classes which are used all over the page.
Is it possible to add a class in the html?
If …
… then in the jQuery instructions you can use the .convert class as trigger for the conversion.
The other blue buttons without the convert-class will not be affected.
If you have to do this for more than one button with the same id (bad!), you’ll have to get the inputs in a different way, as $("#btnViewDetails") will only pull in the first element with that id.
wow thanks Pullo, that is almost working. As you said the first part of code changes the first intance of the link. But I’m having problems getting the second code you posted to work. I’m ammended it below and added a closing " after the input type but that didn’t fix it. Any thoughts? I’ll keep trying also.
Hi, not sure if I should post this in a new thread or not. Let me know. The above fix has been working really well for me but now I’m wondering if i can do the same but with a url? In summary on the click of a button - I want to remove/change a few words in the url and reload the page (then the new url will load). any thoughts? Cheers