Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 853233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:43:36+00:00 2026-05-15T07:43:36+00:00

I have a jquery function(This is not written by me anyway still I am

  • 0

I have a jquery function(This is not written by me anyway still I am learning). In that we are replacing urls using f.attr("href") in several places. I am not understanding that from where this href value will be binded. And why the value(f.attr("href")) is changing place to place. I mean to say it is having some value @ one location and if I give the same it is giving me different value at other location.

I read in article that The .attr() method gets the attribute value for only the first element in the matched set..What is the matched set means

2

Let me modify my question like this: Can I append query string in Jquery function? I want to add two more querystring elements from webpage to get full url. If we can..How can we accomplish that?


.replace("${my_email}", "mailto:my@u.com?subject=Thanku &body=Jquery working.%0A%0ahttp://www.my.site.com/_layouts/products/New.aspx?url=" + f.attr("href")) In this the f.attr("href") is giving me different value than others where we used..Basically it is giving me half of the link only..

Is there any thing that you need I can provide you Thank u

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:43:36+00:00Added an answer on May 15, 2026 at 7:43 am

    When you use a selector in a jQuery call it may match more than one element. The results are returned as a jQuery object, which may contain a collection (array) of matched objects. Some methods, like attr only work on the first element in the collection.

    For example,

    $('a')
    

    will match all anchor tags in your document.

    Now each of these will (may) have an href attribute, but if you apply the attr function to the results of that selector, it will only operate on the first element in the collection. If I have the following HTML.

     <a href='#0'>Zero</a>
     <a href='#1'>One</a>
    

    and use

    var href = $('a').attr('href');
    

    Then the href variable will have #0 as it’s value despite the fact that the selector matches both of the anchors.

    Making it somewhat more confusing is that usually the version of the method that assigns values, rather than read values, will work on all of the elements in the collection. For example,

    $('a').attr('title','foo');
    

    will assign foo to the title attribute of both anchors in the collection. It’s important to understand the differences in the way the various methods operate. See the jQuery API for more details on specific methods.

    In your case, I suspect that f is a variable that matches different selectors in different locations in the code (f is a lousy variable name, btw, making it more verbose would probably help in understanding what the code does). That would explain why it has different values for the href attribute in different locations. Of course, the values could also be changing precisely because you’re setting them, but I would hope you would have understood if that were happening.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a function outside of $(document).ready() , but am still using jQuery
I have written a jQuery plugin like this: jQuery(function($) { $.fn.myPlugin = function() {
i have this jquery function that i want to pass topic parameter to, i
I have this jQuery which works fine $(li[id^='shop_id']).click( function () { alert(I clicked on
I have some jQuery code. I have called an Ajax function file, file.php, that
I have a form I am submitting using jQuery's ajaxSubmit function from the Forms
I have written a simple jQuery script that changes the hash tag of a
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have written a simple jQuery.ajax function which loads a user control from the
This is the piece of code I have written: <html> <head> <script type=text/javascript src=jquery-min.js></script>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.