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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:34:32+00:00 2026-06-09T02:34:32+00:00

I have a div with a link and on click should open a jQuery

  • 0

I have a div with a link and on click should open a jQuery dialog above/within the div itself with fadein and out.

I’ve tried to examplify it with this image: http://img593.imageshack.us/img593/9852/exampled.jpg

HTML

<div id="dialog" title="Basic dialog" style="display: none">Add to cart</div>

jQuery

$('.div').click(function(){
   $('#dialog').fadeToggle();
});

CSS

.div{
    background-color: #fff;
    border: 1px solid #FFECA2;
    width: 123px;
    text-align: center;
    padding: 3px 9px;
    position:relative;
}

#dialog {
    display:block;
    position:absolute;
    display:none;
    left:0; top:0;
    width:100%; height:100%;
    background-color: #FFFEDF;
    border: 1px solid #FFECA2;
    width: 123px;
    text-align: center;
    padding: 3px 9px;
}​

I have put together a fiddle of what I have so far: http://jsfiddle.net/725Me/

Now, the problem is: if i have a lot of div elements, do I have to define

<div id="dialog"> Add to cart </div> for each div? Would it be possible to define it only once?

  • 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-09T02:34:34+00:00Added an answer on June 9, 2026 at 2:34 am

    UPDATED ANSWER:

    If you don’t want to define the <div class="dialog">Add to cart</div> markup for every div, you can use jQuery to apply it the first time each div is clicked. (Notice that I changed the ID dialog to a class dialog instead. An ID have to be unique for each element, which is not going to work if we are going to reuse this code for each div).

    When a div is clicked, we check if the dialog class has been added already, otherwise we append it. Then we fadeToggle() as usual.

    Something like this:

    $('.div').click(function() {
        if ($(".dialog", this).length === 0) {
            $("<div class=\"dialog\">Add to cart</div>").appendTo(this);
        }
        $(".dialog", this).fadeToggle();
    })​;
    

    Your markup would then be a bit simpler:

    <div class="div">
        lorem ipsum dolor sit amete
    </div>
    <div class="div">
        lorem ipsum dolor sit amete
    </div>
    <div class="div">
        lorem ipsum dolor sit amete
    </div>​
    

    A working example: http://jsfiddle.net/725Me/4/

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

Sidebar

Related Questions

I have a hidden div (#contactArea) above another div. When I click the link,
The problem is: I have a div with a link and on click should
how can i select the current link via jquery if I have a div
i have got <div><a class='link' href='index.php' data-container='target'>Load</a></div> <div class='target'></div> i need to write jquery
I have the following code: $(a.sticky-link).click(function (e) { e.preventDefault(); $(div.stickies-box).slideToggle('slow'); $(a.sticky-link).toggleClass(selected); }); $(div.stickies-box).mouseup(function ()
I have an HTML link that opens a jQuery modal dialog which contains an
I have a jquery animation that toggles the width of a div. Within the
I have a few links, which should toggle their corresponding div like this... $('#link
I have a link button inside UpdatePanel in a div popup. On Button_Click, I
So I am trying to have a div slideToggle when this link is clicked.

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.