Solved

Javascript Show/Hide tweak

Posted on 2014-03-25
3
472 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now