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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:07:20+00:00 2026-06-05T07:07:20+00:00

index.php: <html> <head> <script type=text/javascript src=script.js></script> </head> <body> <div id=box></div> <div onclick=getContent()>Open Window</div> </body>

  • 0

index.php:

<html>
    <head>
        <script type="text/javascript" src="script.js"></script>
    </head>
    <body>
        <div id="box"></div>
        <div onclick="getContent()">Open Window</div>
    </body>
</html>

script.js:

function getContent() {
    //ajax call that returns the html from content.php and places it in the box div
}
function sayHello() {
    console.log('Hello');
}
function sayGoodBye() {
    console.log('Good Bye');
}

content.php:

<div onclick="sayHello()">Say Hello</div>
<div onclick="sayGoodBye()">Say Good Bye</div>

What is the correct way to make the functions sayHello() and sayGoodBye() work?
Currently they do nothing.

  • 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-05T07:07:21+00:00Added an answer on June 5, 2026 at 7:07 am

    As your element comes from ajax and append to #box dynamically, so you need an delegate event handling.

    $('#box').on('click', '#newElement', function() {
    
    });
    

    Syntax for delegate of .on() is:

    $(container).on(eventName, target, handlerFunction);
    

    To trigger you need to use

    $('#box div').eq(0).click(); // sayHello()
    
    $('#box div').eq(1).click(); // sayGoodBy()
    

    NOTE

    I think it should work normally

    Look here

    And its also possible to trigger those click events

    Check this

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

Sidebar

Related Questions

index.php <!DOCTYPE html> <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <title>Form submit in php
I have a PHP script (index.php) that includes an index.html file in a sub-directory
I need a rewriterule so if i type index.html i will show index.php I
My index.php contains a bunch of php and javascript code, and html formatted in
Let's say i have an index.php that has html in it that looks like
I'm developing web page which has main file index.php as follows: include('UserClass.php'); include('html/top.php'); $user
There is a website in Joomla, the NavigationPath ist domain.tld/index.php/produkte/produkt1.html this work fine. But
The script is in myusername/public_html/item/index.php code to save file: $filename = $_SERVER['DOCUMENT_ROOT'].'/../data/guestbook.txt'; $filehandle =
I have a post html form, and the action is index.php, which is the
If I include an HTML page on a PHP page (say, index.php) with the

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.