Solved

Get Toggle show/hide to work with Text, instead of images

Posted on 2013-02-02
6
1,262 Views
Last Modified: 2013-02-03
Chris assisted with this code on the previous thread (Code below).
http://www.experts-exchange.com/Q_28015231.html#a38839928

This code works with images, however, I also need to make it work with Text.
As I love how this works, and I am wanting to convert all my show/hide functions to this.

Thanks all;
Carrzkiss
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){  
	$('.ahref').click(function() {
		$(this).toggleClass('hidden'); //change the status of the link
		$($(this).data('div')).slideToggle(500); //toggle the visibility
	});
});
</script>

<style type="text/css">
	.ahref { background: url(http://cdn1.iconfinder.com/data/icons/diagona/icon/16/130.png) no-repeat left top; width: 16px; height: 16px; display:inline-block; cursor:pointer; }
	.hidden { background: url(http://cdn1.iconfinder.com/data/icons/diagona/icon/16/129.png) no-repeat left top; } 
</style>

<a class="ahref" data-div=".box1"></a>
<a class="ahref" data-div=".box2"></a>
<a class="ahref" data-div=".box3"></a>

<div class="box1">1</div> 
<div class="box2">2</div> 
<div class="box3">3</div>

Open in new window

0
Comment
Question by:Wayne Barron
6 Comments
 
LVL 14

Expert Comment

by:dejaanbu
ID: 38847989
now, what is the pbm with your attached code? can u elaborate?
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38848018
as stated in the description.
This is with images, I need it to show text instead.

Show
Hide

Instead of the "Images"

This script was updated from the old text show/hide version.
As the older version would not work with the new jquery framework.
So, I am lost as to the way it needs to be coded, in order to hold the text.

You can chose text links, they just will not change once they are clicked on.

Carrzkiss
0
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 250 total points
ID: 38848201
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){  
	$('.ahref').click(function() {
                 var th = $(this);  // store this in a variable so performance increases
		th.toggleClass('hidden'); //change the status of the link
                 if (th.hasClass('hidden')) {
                       th.text('Show');
                 } else {
                       th.text('Hide')
                 }

		$($(this).data('div')).slideToggle(500); //toggle the visibility
	});
});
</script>

<style type="text/css">
	.ahref { display:inline-block; cursor:pointer; } 
</style>

<a class="ahref" data-div=".box1">Show</a>
<a class="ahref" data-div=".box2">Show</a>
<a class="ahref" data-div=".box3">Show</a>

<div class="box1">1</div> 
<div class="box2">2</div> 
<div class="box3">3</div>

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Expert Comment

by:mokatell
ID: 38848411
Try This :       

-----> Style

#menuItems
{
width:960px;
display:none;
}

------> Html Tags

                 <ul ><li id="link"><span style="cursor:default"  >Hello</span></li></ul>

                $("#link").mousedown(function() {
                $("#menuItems").slideToggle(200);
                  });
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 250 total points
ID: 38848721
Here's another fiddle using text instead of images:

http://jsfiddle.net/ChrisStanyon/5REJa/
0
 
LVL 30

Author Closing Comment

by:Wayne Barron
ID: 38848815
Thanks guys.
I accepted both working examples, however, I will be going with Chris's code, as it is the most simplified of the 2.

Thanks a bunch guys.

Take Care
Carrzkiss
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now