Check if div is hidden to decide whether to slideDown or slideUp

Posted on 2013-09-01
Medium Priority
Last Modified: 2013-09-04

I currently have this script which slides down hidde content when a trigger is clicked, it also changes the text from 'More' to 'Less' and the image from a down arrow to an up arrow.
Firstly is there a more efficient way of doing it and also I need to add an action so that if the content is now shown and the text and image changed then the next time a user clicks it slides Up.

function toggleslideDown (activator, selector) {
					$(this).children('img').attr('src', 'img/up-arrow.png');

Open in new window

Question by:Al4ddin2
  • 2
LVL 43

Expert Comment

ID: 39457214
I think you're just looking for an accordion, such as this one?
That should make it easier
LVL 83

Expert Comment

ID: 39457226
your code updated :
function toggleslideDown(activator, selector) {
        var text = $(this).find('span').text();
        var b = text == "Less";
        if(b) $(this).prev('section').find(selector).slideDown(); else $(this).prev('section').find(selector).slideUp();
        $(this).children('img').attr('src', b:'img/down-arrow.png'?'img/up-arrow.png');

Open in new window


Author Comment

ID: 39460195
Thanks leakim971,
I have tweaked it slightly but I am getting an error on this line:

$(this).children('img').attr('src', b:'img/down-arrow.png'?'img/up-arrow.png'); 

Open in new window

Error: SyntaxError: missing ) after argument list
LVL 83

Accepted Solution

leakim971 earned 2000 total points
ID: 39460215
$(this).children('img').attr('src', b?'img/down-arrow.png':'img/up-arrow.png'); 

Open in new window


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

600 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