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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:16:07+00:00 2026-06-17T12:16:07+00:00

I have my code here. // HTML Code <div class=article></div> // jQuery $(‘.article’).append(‘<a href=

  • 0

I have my code here.

// HTML Code
<div class="article"></div>

// jQuery
$('.article').append('<a href="" class="toggle">Toggle div</a>');

Is it possible to use that newly created href link and toggle a div like this:

// jQuery
$('.toggle').click(function() { 
   $('.article').toggle('slow');
});

I have tried the above with no luck. I just get redirected to index page.

  • 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-17T12:16:08+00:00Added an answer on June 17, 2026 at 12:16 pm

    Don’t use click(): it’s deprecated and wouldn’t work even if it weren’t. Use on():

    $('.toggle').on('click', function() { 
       $('.article').toggle('slow');
    });
    

    Also, change your a tag to <a href="javascript:void(0)" class="toggle">Toggle div</a>.


    As to the reason why on() works and click() doesn’t, you need to read jQuery’s documentation. In short, the click event has been bound to an element on the page; this scope does not cover future elements that are added to the DOM. On(), however, is a delegated event:

    Delegated events have the advantage that they can process events from
    descendant elements that are added to the document at a later time. By
    picking an element that is guaranteed to be present at the time the
    delegated event handler is attached, you can use delegated events to
    avoid the need to frequently attach and remove event handlers.

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

Sidebar

Related Questions

I have this html code that i want to edit with jQuery. Here is
Hi I have this HTML code <th scope=col class= style=width: 13px;> <div class=some-handle></div> <a
I have a HTML structure like this:- <article id=a_post class=a_post> <div id=thumbnail> <img id=shine
i just want to ask about my html code here, i have a bit
I have a simple situation here. lets face html code first => <form name=geoKey
I have a form which is located here, http://brandybrowauto.com/npo3.html , and the code is
I have this code here, {foreach from=$cart.cartItems item=item name=cart} <div id=cart2Produkt> <p>{if $item.Product.ID} <a
LIVE CODE I'm trying to have my maincontent div class=mc just appear on the
enter code here I am having a little problem with jquery.empty(). I have some
Okay, here's my problem. I have a page where I use toggle to show/hide

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.