?
Solved

Jquery graphic and text swap

Posted on 2010-09-01
3
Medium Priority
?
392 Views
Last Modified: 2012-05-10
Hi, I am building a page which uses Jquery slidetoggle to reveal a map when clicked. The text on the box initially says 'View the interactive map' and has an arrow pointing downwards.

What I want is when the map is visible (once clicked), the words to then change to 'Close the interactive map' and the arrow to change upwards.

My page is here - www.soundyoucansee.com/map

Can anyone help?
<script type="text/javascript">
       $(function() {
            $("#toggle").click(function() {
                $("#toggleMap").slideToggle("slow");
           });
        });
		 </script>

Open in new window

0
Comment
Question by:matreece
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
hrgdavor earned 2000 total points
ID: 33578103
add another div like
and replace the script with the script provided
<div id="toggle2" style="display:none"><img src="img/ArrowUp.png" width="9" height="6" /> Hide the Interactive Map</div>
<script type="text/javascript">
       $(function() {
            $("#toggle").click(function() {
                $("#toggleMap").slideDown("slow");
                $("#toggle").hide();
                $("#toggle2").show();
           });
            $("#toggle2").click(function() {
                $("#toggleMap").slideUp("slow");
                $("#toggle2").hide();
                $("#toggle").show();
           });
        });
</script>

Open in new window

0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 33579344
Try this:


<script type="text/javascript">
$(function() {
	$("#toggle").click(function() {
		$("#toggleMap").slideToggle("slow",function(){
			if($(this).is(':visible')){
				var img = $("#toggle").find('img').attr('src','img/ArrowDown.png')
				$("#toggle").html(' Hide the Interactive Map').prepend(img)
			}else{
				var img = $("#toggle").find('img').attr('src','img/ArrowUp.png')
				$("#toggle").html(' View the Interactive Map').prepend(img)
			}
		});
   });
});
</script> 

Open in new window

0
 

Author Closing Comment

by:matreece
ID: 33584417
This is great. Worked 1st time with no problems.
0

Featured Post

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

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

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

770 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