/    Sign up×
Community /Pin to ProfileBookmark

Keep size of div area on toggle

I have the following code. Functionally, it’s working great, but when you toggle between button 1 and button 2 and the div slides into position, the size of the div collapses. I’d like to make it so that the page doesn’t resize when toggling back and forth. I’m figuring this is an easy fix, but I can’t seem to get it right. Code is below. Any help is much appreciated. Thank you in advance!

[CODE]
<script src=”//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”></script>

<script>
$(function () {
$(“[name=toggler]”).click(function () {
$(‘.toHide’).hide();
$(“#blk-” + $(this).val()).show(‘slide’);
});
});
</script>
[/CODE]

[code=html]
<label>
<input id=”rdb1″ type=”button” name=”toggler” value=”1″ />
</label>
<label>
<input id=”rdb2″ type=”button” name=”toggler” value=”2″ />
</label>

<div id=”blk-0″ class=”toHide”>
<div class=”center-form-img” >
<img src=”{{media url=”wysiwyg/form-inactive.jpg”}}” alt=”” />
</div>
</div>
<div id=”blk-1″ class=”toHide” style=”display:none”> {{block type=core/template name=ContactUs template=cmg/ContactUs1.phtml}}</div>
<div id=”blk-2″ class=”toHide” style=”display:none”>{{block type=core/template name=ContactUs template=cmg/ContactUs2.phtml}}</div>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@TcobbSep 25.2013 — Incorporate something along these lines when the button is clicked:


[CODE]//assume the variable 'div' is the reference to the div in question

div.style.height = div.offsetHeight + 'px';
div.style.width = div.offsetWidth + 'px';[/CODE]
×

Success!

Help @frshjb373 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...