Prevent pushing elements on hide and show - jQuery

382 Views Asked by At

I'm hiding and showing the contents inside fieldset on click of legend.

JSFIDDLE Example

 var legends = document.getElementsByTagName("legend");

    for(var i=0; i<legends.length; i++)
    {
        legends[i].onclick = function()
        {
            var myDivs = this.parentNode.getElementsByTagName("div");
            var myDiv;

            if(myDivs.length > 0)
            {
                var myDiv = myDivs[0];

                if(myDiv.style.display == "")
                {
                    myDiv.style.display = "none"
                }
                else
                {
                    myDiv.style.display = "";
                }
            }
        }
    }

How do i prevent pusing after showing the contents? In my example Sample content is pushed down after the contents are shown. How to overlap div contents?

1

There are 1 best solutions below

0
On

I would suggest showing it in a popup if you are using jquery. Try this code in the html and make sure you reference jquery mobile:

<a href="#popupBasic" id="tet" data-rel="popup"><legend>One Legend</legend></a>

<div data-role="popup" id="popupBasic">
    <fieldset>

    <div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.e</div>

</fieldset>
</div>
<div><text>Sample Content</text></div>

jsfiddle: https://jsfiddle.net/UHn6q/51/