Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reposition div based on click location

Tags:

html

jquery

I have a page that contains multiple, identical hidden forms, each contained in a separate hidden DIV as such:

HTML:

<div class="product-intro-text">Some text....
    <div class="rfq-button"><a class="advantage-button" id="Adapters" href="#">Request a Quote</a></div>
    <div class="inline-rfq">
            <form class="contact" name="contact" action="#" method="post">...</form>
    </div>
</div>
<div class="h-sep"></div>
<div class="product-intro-text">Some text....
    <div class="rfq-button"><a class="advantage-button" id="Auger&nbsp;Equipment" href="#">Request a Quote</a></div>
    <div class="inline-rfq">
            <form class="contact" name="contact" action="#" method="post">...</form>
    </div>
</div>

Instead of having all of these identical hidden DIVs, how can I reposition the .inline-RFQ DIV to appear below the corresponding .rfq-button that was clicked? This is for a mobile site, so solutions would have to be mobile-friendly.

I'm already using JS/JQuery throughout the rest of the page and here is the JS that reveals the hidden DIV:

   jQuery(document).ready(function($){
/* toggle form */
$(".rfq-button").on("click", function(){
    $(this).next().slideToggle();
    $(".inline-rfq").next().toggleClass("display");
});
});

Thanks for your help in advance.

like image 876
Peter Susko Avatar asked Dec 19 '12 14:12

Peter Susko


1 Answers

Here's a fiddle: http://jsfiddle.net/psyon001/ejdgX/ One thing you may want to add is reseting the form states when showing under a new section.

jQuery(document).ready(function($) { /* toggle form */
    $(".rfq-button").on("click", function() {
        var $thisParent = $(this).closest('.product-intro-text'),
            $form = $(".inline-rfq");
        if ($thisParent.find('.inline-rfq').length) {
            $form.slideToggle();
        } else {
            $form.slideUp(function() {
                $form.appendTo($thisParent).slideDown();
            });
        }
    });
});​
like image 51
Syon Avatar answered Oct 21 '22 06:10

Syon