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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:16:40+00:00 2026-05-22T19:16:40+00:00

I have 3 files: js_json.js -> for my json code javascript.js -> for my

  • 0

I have 3 files:

  • js_json.js -> for my json code
  • javascript.js -> for my javascript
    function
  • index.php

Here the code for js_json.js:

$(function(){
    $('#postTitle').change(function(){

        var title_id = $("#postTitle").val();


        $.ajax({
            type:"post",
            url:"proses.php",
            data:"title_id=" + title_id,
            dataType:"json",
            success:function(data){
                body="";
                //$.each(data, function(i,n){
                    //body = n['body'];    
                //});
                body += "<a href=\"javascript:void(0);\" id=\"pesan\" name="pesan" onClick=\"\">Hola Test</a>";
                $(".postBody").empty();
                $(".postBody").append(body);
            },
            error:function(data){
                $(".postBody").empty();
                $(".postBody").append("NO Post Selected.");
            }

        });
        return false;
    });
});

and here my javascript.js code:

$(function (){
    $("a[name=pesan]").click(function (){
        alert("holalalalalal.....!");    
    });
});

and here the index.php code:

    //some code
    <body>
        <a href="javascript:void(0);" id="pesan" name="pesan">Hola Test 1</a>
        Posts : <br />
        <select name="title" id="postTitle">
            <option value="">Select Post...</option>
            <?php
                $sql = "SELECT id, title FROM posts ORDER BY title";
                $query = mysql_query($sql) or die(mysql_error());

                while($rows = mysql_fetch_array($query)){
                    print('<option value="' . $rows['id'] . '">' . $rows['title'] . '</option>');
                }
            ?>
        </select>
        <br />
        Body : <br />
        <div class="postBody">
            Will show the body of post.
        </div>
    </body>
</html>

and my question is:

When I click the link “Hola Test 1”, it works and the message appears. The problem is, after I click the select option, and the link “Hola Test” appears, and then I click that (“Hola Test”) link, the message does not appear and there are no errors in firebug…

Can somebody explain to me why…? Thank’s…

  • 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-22T19:16:42+00:00Added an answer on May 22, 2026 at 7:16 pm

    click() will only bind the event for elements that exist in the page at the time click is called (the same goes for on() without a selector, bind(), and all the other methods in the shortcut-group for bind; keydown(), change() etc. ).

    Because your other element is getting added via AJAX some time later, the handler isn’t bound for it.

    Use .on() with a selector instead, which will bind the event to all current and future elements matched by the selector.

    $(function (){
        $(document).on('click', 'a[name=pesan]', function () {
            alert("holalalalalal.....!");    
        });
    });
    

    Since on() was introduced in jQuery 1.7, if you’re using earlier versions of jQuery (like those that existed when this question was asked), you can use live() or delegate() instead of on;

    $(function (){
        $('a[name=pesan]').live('click', function () {
            alert("holalalalalal.....!");    
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with the json.getJSON method. Here is my current code: var
I'm developing a website in PHP and I have large JS files that I
I'm probably missing something very obvious here. I have files with the extension .st
I have the following structure: -uploadpage.html -index.php -resources -jquery-1.4.2.min.js On my index.php, I get
I'd like to execute JavaScript code from within a C# assembly and have the
I have a bit of JavaScript code that is specified in a configuration file
I now have a working JavaScript autocomplete function, thanks to help from many of
I have a javascript function that has been driving me nuts. This is the
i have the file 1.html: ..... <script src=/libs/jquery-1.3.1.min.js type=text/javascript></script> <script type=text/javascript> var url0='{$url0}'; var
I have some constants in JavaScript that I'd like to reuse in several files

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.