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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:52:43+00:00 2026-06-04T01:52:43+00:00

I am having trouble getting an .on ‘click’ function to work upon AJAX loaded

  • 0

I am having trouble getting an .on ‘click’ function to work upon AJAX loaded content.

I have worked with the jquery .live before but this is the first time with .on and understand it works in the exact same way so unsure why I am having problems.

Below is the HTML that gives the element to which you click on

    <h1>Press &amp; Media</h1>
    <div id="back"></div>
    <div id="overlay-content">
        <span id="edocs" class="tab"></span>
        <span id="news" class="tab"></span>
        <span id="partners" class="tab"></span>
    </div>

Below is the function that loads the AJAX content.

    $("#overlay-content").on('click','#news',function() {
        var active = 1;
        $("#loading").show();
        $("#overlay-content").fadeOut(1000, function() {
            $.get("http://<? echo ROOT; ?>includes/functions.php", { pressmediaNews: active }, function(data) {
                $("#loading").hide(400);
                $("#overlay-content").empty().append(data).fadeIn(1000);
            });
        });
    });

This should load the following HTML

    <div id="news-left-panel">
        <h4>News Section</h4>
        <ul>
            <li id="newsID2" class="newsYear">
                <p>2012</p>
                <ul class="newsMonths" style="display:none">
                    <li>Jan
                        <ul class="newsArticles" style="display:none">
                            <li onClick="newsID(2)">test</li>
                        </ul>
                    </li>
                    <li>Feb</li>
                    <li>Mar</li>
                </ul>
            </li>
            <li id="newsID1" class="newsYear">
                <p>2011</p>
                <ul class="newsMonths" style="display:none">
                    <li>Dec
                        <ul class="newsArticles" style="display:none">
                            <li onClick="newsID(1)">Test</li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div>

Now the above code simply wont execute, show any errors etcetera in firebug.

So I’m a bit lost as to why it wont execute, the alert() even does not execute.

  • 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-04T01:52:44+00:00Added an answer on June 4, 2026 at 1:52 am

    First make sure you’re hitting the target, try this and see if the alert shows :

    $(function() {
        $(document).on('click', '#news', function() {
           alert('ok');
        });
    });
    

    If the alert shows when clicking the #news element, it’s ok.

    Now to this line:

    $.get("http://<? echo ROOT; ?>includes/functions.php",
    

    You are using the shorthand PHP opening, and that needs to be turned on, you could try

    <?php echo ROOT; ?>
    

    But what the frack is ROOT, never seen that before, and could not find anything in the PHP manual on ROOT, so I tried on my own server with the newest version of PHP, and got an error as ‘ROOT’ does not exist, instead it assumed it was a string and just echo’ed “ROOT”, so your link would look like:

    $.get("http://ROOTincludes/functions.php",
    

    It it’s a variable you have defined somewhere yourself, it should start with a dollarsign, if it’s something you’ve defined with define(), make sure it’s set up correctly and if it’s using something like $_SERVER['DOCUMENT_ROOT']; that’s not always something you can access in javascript as it will normally be a folder that is higher then your webroot, and can’t be accessed on the clientside but only on the serverside.

    Also, the way you have written it, starting with http:// it should be a domain name.
    Try opening view source in you browser and find your ajax function and see what ROOT actually outputs, as the final ouput will be visible in the source, and if it’s set using define() in an included config file etc. you can see that it was set up correctly.

    Your javascript would also have to be inside a PHP file for PHP to execute, or you would have to modify your server setup to run JS files thru PHP.

    In my opinion just using a path and filename is the right way to do it, try this and pay attention to the console (F12) :

    $(document).on('click','#news',function() {
        var active = 1;
        var XHR = $.ajax({
                       type: 'GET',
                       url : '/actualpath/includes/functions.php',
                       data: { pressmediaNews: active }
                  }).done(function(data) {
                       console.log(data);
                  }).fail(function(e1, e2, e3) {
                       console.log('error : '+e1+' - '+e2+' - '+e3);
                  });
        $("#loading").show();
        $("#overlay-content").fadeOut(1000, function() {
            XHR.done(function(data) {
                $("#overlay-content").empty().append(data).fadeIn(1000);
                $("#loading").hide(400);
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble getting the following code to work: $('#changeMode').button().click(function(){ $('#playfield').toggle(function() { $(this).switchClass(gridView,plainView); }, function()
Having trouble getting success from this... <!-- Ajax --> <script type=text/javascript> $('a.clickup').click(function (event) {
Having trouble getting this to work. What's strange is that I have 10 bookmarks
I'm having trouble getting Jquery .closest() to work. Here's my code, it's simple and
I am having trouble getting this to work. I have variables initiated in main
I'm having trouble getting my callback function to work in post: I've got this
I am having trouble getting jQuery ajax to recognise a session. I am creating
I am having trouble getting my chat application working correctly. I have 2 textbox's,
I am having trouble getting one of my LINQ to SQL queries to work
Having trouble getting JQuery to access the parent form field 'inputStart's value when a

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.