Solved

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

Posted on 2013-02-02
6
1,256 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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 42

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 46
Hovering effect 9 29
Phone Dialer 5 37
Cross domain request in Javescript 9 29
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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.
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…

760 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

22 Experts available now in Live!

Get 1:1 Help Now