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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:22:57+00:00 2026-06-10T19:22:57+00:00

Hi and thanks for reading. I’ve been trying to avoid using HTML onclick=__ references

  • 0

Hi and thanks for reading. I’ve been trying to avoid using HTML onclick="__" references and instead putting these events in my .js file. After reading about jQuery’s .click() and then .on() events, I tried to use this in my code for a button.

edit In my haste to make up a <p> that didn’t have the rest of the contents, I entered “name” instead of “id”. Many answers have recommended I either switch to a p[name=p+ or #p+ reference, but my main problem has been that I can’t even hit the alert before the reference to the id/name. Thanks again for your answers.

HTML:

<p name="pBananas"> junk </p> 
<button class="deleter" id="dBananas" name="Bananas">Delete</button>

JS:

$(document).ready(function() {
    $('.deleter').click(function() {
        alert('click function works');
        $("p" + $(this).attr("name")).remove();
    });
});

The above code won’t even get to the alert when I click the button. I’ve also tried referring to the button by name and ID, and going by $(document).ready($('.deleter')___.

I tried using the $(handler) format as well to have the click event be set after the document is ready. Neither way seems to work. At this point, I resorted to onclick="deleteButton()" and have a deleteButton() function in my .js file, but the function won’t detect $(this) and just deletes all <p> tags.

The rest of my javascript is working. I haven’t tried including this .on() at the bottom of the HTML, but I’m trying to avoid scripts in my HTML as well. For completeness’ sake, I’ve been testing on both Chrome and Firefox, using a .jsp file to render the HTML.

Thanks again.

Edits

here’s how I’m referencing my jquery and js, directly copy-pasted.

<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="javascript/index.js"></script>
</head>

here is how my html looks leading up to the div where the

is inserted:

<body>
    <div id="wrapper">
        <div id="header">Card Draw Probability Calculator</div>
        <div id="main">
            <div id="cardList">
                <fieldset>
                    <legend> Select cards for probability calculation</legend>

                        <div id="innerCardList"></div>

Here is how the <p> is generated:

function newestCardListLineMaker() {
    var $newLine = $('<p id="newestPara"><input type="checkbox" name="new" value="none"/> <input class="cardText" type="text" maxlength="30" name="newestCard" /> Quantity <input type="text" maxlength="1" class="quantityText" name="newestQuant" /><button class="deleter" id="newestDelete">Delete</button><br/></p>');

    $("#innerCardList").append($newLine);

On another note, which I should have seen before as significant: the HTML that the .click or .on(click, handler) is referencing has been created by another js function.

  • 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-10T19:22:59+00:00Added an answer on June 10, 2026 at 7:22 pm

    Try using .on() function, so your code would be:

    $(document).ready({
      $('.deleter').on('click', function(){
         //do stuff here
      });
    });
    

    Even better would be this:

    $(document).ready({
       $('div_above_.deleter').on('click', '.deleter', function(){
         // do stuff here
       });
    });
    

    Hope this helps you.

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

Sidebar

Related Questions

Thanks for reading this ... I've been searching and experimenting for 3 days trying
thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to
Hello and thanks to everyone for reading my question. I've been working on a
Thanks for reading. I'm trying to put a label and an image on a
Hi and thanks for reading this. I am trying to use the IF EXISTS/IF
Thanks for reading. I'm trying to use CoreImage in iOS 5 to alter the
Hi and thanks for reading. I am using the ICallbackEventHandler interface to do some
Thanks for reading this. I have markup similar to what is below. Using the
Thanks for reading! var data = <html><head><title>Hello</title></head><body>Hello Body</body></html>; I want to print data including
Thanks for reading! I am using the Android Gallery tutorial and wondering if there's

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.