Solved

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

Posted on 2013-02-02
6
1,270 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
[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
6 Comments
 
LVL 14

Expert Comment

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

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 31

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Rhino Java Array in Javascript 1 39
email validation 9 49
Link Anchor Not working 9 49
Hide and Unhide Table 6 27
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
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…

726 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