Append a url query parameter all elements that have a css class of "appendServiceID"

Dear Experts,

I want to use JQuery to append a url query parameter to the "href" of each element that has the cssclass "appendServiceID". How can this be done?

I want something like this

for each element which has cssclass "appendServiceID"
   if this element has an "href"
      href.src = href.src + "&servideID=100"
Who is Participating?
Albert Van HalenAnalyst developerCommented:
use this
It also checks if the link contains a question mark
$("A.appendServiceID").each(function() {
    if(this.href != "") {
        if(this.href.indexOf("?") == "-1")
            this.href+= "?servideID=100";
            this.href+= "&servideID=100";

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.