Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2013, 03:01 PM   PM User | #1
paddyfields
Regular Coder

 
Join Date: Dec 2010
Location: London
Posts: 278
Thanks: 60
Thanked 11 Times in 11 Posts
paddyfields is an unknown quantity at this point
Question replace div with slidedown() animation

Hi, I've hit a brick wall with this as my JavaScript isn't too great.

I want to have a link than when clicked replaces the div contents (of which the link is in) with something different, but revealed via a jQuery slideDown() animation. So essentially you click the link, it disappears and a div slides down and appears in it's place. It is for a 'show more options' feature.

I've managed to make two scripts, one that has the slideDown() feature working, and one that replaces the content of the div once clicked, but I really can't work out how (or if) it is possible to combine them to achieve my aim? Or is there a better way to do this? Any help would be amazing!

slidedown
Code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<style type="text/css">
    .showOptions {
        float:left;
        padding:8px;
        margin:16px;
        border:1px solid red;
        width:400px;
        height:200px;
        background-color:#eee;
        color:white;
    }
</style>
<div class="showOptions">
    <a href="javascript:;" onclick="changeContent" ;>show options</a>
</div>
<script type="text/javascript">
    $(".showoptions").click(function () {
        $(this).hide().slideDown('slow');
    });
</script>
<script type="text/javascript">
    var newContent = 'these are the options!';

    function changeContent(idstr) {
        document.getElementById('show-options').innerHTML = newContent;
    }
</script>
replace div
Code:
<script type="text/javascript">
    var newContent = 'these are the options!';

    function changeContent(idstr) {
        document.getElementById('show-options').innerHTML = newContent;
    }
</script>
<div id="show-options">
    <a href="javascript:;" onclick="changeContent();">show options</a>
</div>

Last edited by paddyfields; 01-29-2013 at 03:07 PM..
paddyfields is offline   Reply With Quote
Old 01-29-2013, 03:48 PM   PM User | #2
paddyfields
Regular Coder

 
Join Date: Dec 2010
Location: London
Posts: 278
Thanks: 60
Thanked 11 Times in 11 Posts
paddyfields is an unknown quantity at this point
I tried all day then worked it out soon after posting... but if anyone is interested;

This replaces the content, then replaces the class, and animates the new content.

Code:
$("#show").click(function () {
    var newContent = 'these are the options!';
    document.getElementById('show-options').innerHTML = newContent;
    $("#show-options").removeClass("showOptions");
    $("#show-options").addClass("showOptions2");
    $("#show-options").hide().slideDown('slow');
});
paddyfields is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:53 PM.


Advertisement
Log in to turn off these ads.