Solved

Javascript Show/Hide tweak

Posted on 2014-03-25
3
476 Views
Last Modified: 2014-03-28
I have a simple javascript "show/hide" snippet I am using to show more content.

Use clicks "see more" and content drops down. He clicks "hide" and the content slides back up and away.

Problem is I would like to hide the "See more" once its clicked and show it again when "hide" is clicked.

Here is the Javascript:

<script type="text/javascript">
 
$(document).ready(function(){
 
        $(".slidingDiv").hide();
        $(".show_hide").show();
 
    $('.show_hide').click(function(){
    $(".slidingDiv").slideToggle();
    });
 
});
 
</script>

Open in new window


And here is the Div that is being shown/hidden:

<div class="slidingDiv">Content of showhide div</div>

Open in new window


and here are the two, identical show and hide links which obviously have the same basic affect:

<a href="#" class="show_hide">(see more)</a>

<a href="#" class="show_hide">(hide)</a>

Open in new window


Any thoughts on modifying this to hide the See More would be great
0
Comment
Question by:mcpilot1
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39953771
http://jsfiddle.net/GaryC123/TEhte/

<a href="#" class="show_hide">(see more)</a>
<div class="slidingDiv">Content of showhide div</div> 

Open in new window

$(document).ready(function(){
    $(".slidingDiv").hide();
    $('.show_hide').click(function(){
        varText=($(this).text()=="(see more)")?"(hide)":"(see more)"
        $(".slidingDiv").slideToggle();
        $(this).text(varText)
    });
});

Open in new window

0
 

Author Comment

by:mcpilot1
ID: 39961442
Gary,

INterestingly, while it's working on your code site, it's not working on the actual site. I have replaced the script in the header, basically overwriting the original version that I posted and it's not working. The "See More" is not appearing at all, despite being vieeable in the source code.

It should be a jquery conflict because the original code worked, and this is but a minor variation of that. I have attached the entire source code as an attachment since this is a shopify file and it's nearly impossible to view the dev site.

Thanks
shopify.txt
0
 
LVL 58

Expert Comment

by:Gary
ID: 39961805
You have this in your css - stylesheet.css line 513

.show_hide {
    display: none;
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Find out what you should include to make the best professional email signature for your organization.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question