Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-02-02
6
Medium Priority
?
1,287 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 44

Accepted Solution

by:
Chris Stanyon earned 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
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…
Suggested Courses

604 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