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 8266255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:05:29+00:00 2026-06-08T05:05:29+00:00

I have this code: <script> $(document).ready(function () { $(‘#lnk’).click(function(e) { e.preventDefault(); url = $(this).attr(‘href’);

  • 0

I have this code:

<script>   
$(document).ready(function () {
    $('#lnk').click(function(e) {
        e.preventDefault();
        url = $(this).attr('href');
        $("#content").load(this.href);
    });

});
</script>

<a href="http://google.com" id="lnk">Google</a>
<a href="http://gmail.com" id="lnk">Gmail</a>
<div id="content">

</div>

When I click the first link (google) it works and load content to my content div. However, when I click second link (gmail) it doesn’t work.

Can anybody help me understand this behavior?

  • 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-06-08T05:05:30+00:00Added an answer on June 8, 2026 at 5:05 am

    IDs are unique, you cannot have multiple elements with the same ID ($('#lnk') will get the 1st element). Use classes instead

    <script>   
    $(document).ready(function () {
        $('.lnk').click(function(e) {
            e.preventDefault();
            $("#content").load(this.href);
        });
    
    });
    </script>
    
    <a href="http://google.com" class="lnk">Google</a>
    <a href="http://gmail.com" class="lnk">Gmail</a>
    

    Also, this will not work, as you cannot use .load to load arbitrary URLs. That’s called the same origin policy.

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

Sidebar

Related Questions

I have this code : <script type=text/javascript> $(document).ready(function() { $('a[name=linkArtist]').click(function(e) { e.preventDefault(); $('#changeArtist').val($(this).attr('title')); });
Say I have this code in my page: <script language=javascript> $(document).ready(function() { $(.test).click(function() {
I have a JS code like this <script type=text/javascript> $(document).ready(function(){ $('.main').on('click', '.block', function (){
i have this code, that works without any problem: <script> $(document).ready(function () { $(.block1).click(function
I have this code: <script type=text/javascript> $(document).ready(function() { var url = https://graph.facebook.com/search?q=cinema&type=post; $.ajax({ type:
i have this code: <script type=text/javascript> $(document).ready(function() { function doAjax(url) { $(#customForm).submit(function() { var
I mean I have this code: <script> $(document).ready( function() { $('html, body').animate({ scrollTop: $(.error).offset().top
I have this code running great in ff, opera and chrome: <script type=text/javascript> $(document).ready(function(){
I have (basically) this code - <script type=text/javascript language=javascript> $(document).ready(function() { $(#loadDiv).load(mypage.html, function(){ alert($(#someText).text())
I have this code: <script type=text/javascript> $(document).ready(function() { $(#iframeId).contents().find(body).append($(#test)); }); </script> <iframe id=iframeId name=iframeId

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.