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

  • SEARCH
  • Home
  • 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 8224065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:55:39+00:00 2026-06-07T14:55:39+00:00

How can I prevent default event action on html elements loaded after dom has

  • 0

How can I prevent default event action on html elements loaded after dom has been created.
I have page which includes another page via jquery .load method as you can see in first line of code.

Code starting from third line does not seem to work.When I click the link with a.clearCart the browser just loads the page instead of requesting page in background.
The link with class clearCart is located in separate file called ‘Cart.php’ which is loaded when page is ready.

Page below is :index.php

$(document).ready(function(e) {
    $('#cart').load('./ajax/Cart.php');//a.clearCart is located in this file    



    $("a.clearCart").click(function(e)
    {
        e.preventDefault();
        return false;
        $.getJSON('./ajax/clearCart.php?','id=12',check);
        function check(data)
        {
            if(data.Status == "Success")
            {
                alert("Update Cart");//For Debugging Only,should call UpdateCart()
            }
            else if(data.Status == "Failed")
            {
                alert("WTF");//Welcome to Finland
            }
        }
    });





    function UpdateCart()
    {
        $('#cart').load('./ajax/Cart.php');
    }
    $('.formInfo form').submit(function(e) {

        var id = this.prodId.value;
        var qta = this.qty.value;
        var data = {prodId:id,qty:qta};
        $.getJSON('./ajax/addcart.php',data,processData);

        function processData(data)
        {
            if($('p.message').text().length > 5)
            {
                $('p.message').empty().removeClass('.success').removeClass('failure');

            }
            if(data.Status == "Failed")
            {
                $('p.message').append(data.Reason).addClass('failure');
            }
            else if(data.Status == "Success")
            {
                $('p.message').append(data.Reason).addClass('success');
                UpdateCart();
            }
        }

        return false;
    });


});
  • 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-07T14:55:40+00:00Added an answer on June 7, 2026 at 2:55 pm

    You can use live() or on() function. I will show with on() because live() is deprecated as of jQuery 1.7:

    Change

    $("a.clearCart").click(function(e)
    

    To

    $(document).on('click', 'a.clearCart', function(e) {
        // Code goes here
    }).
    

    See

    • http://api.jquery.com/live/ – Deprecated as of jQuery 1.7
    • http://api.jquery.com/on/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does a List have a property or mechanism by which I can prevent duplicate
Can anyone point me to the documentation of the html Event object? Bonus Reading
I have a dashboard page where the user can enter an asset code or
I have to prevent Coldfusion's default list delimiter ',' from being entered into a
I have an live event on all link or multiple selector on the page
I have a jquery/ajax form that has event.preventDefault() . The problem is that my
If one can prevent subclassing by declaring private constructor in the base class, why
I am wondering how I can prevent a crash when trying to close UIDoc
Hi I want to write an application that can prevent other application from using
How can I prevent an application from rendering the viewscript with any parameters. So

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.