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

Posted on 2009-04-20
Last Modified: 2012-05-06
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"
Question by:vbhargav80
    1 Comment
    LVL 19

    Accepted Solution

    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


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now