Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
jQuery: Show info box when clicked
Old 04-30-2009, 06:21 PM jQuery: Show info box when clicked
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
Basically, there's a list of facts and when one fact in the list is clicked, I want the fact information box in the same div as the fact (which is defined as class "fact") to appear. However my attempt seems to be .. incorrect.. any suggestions?

HTML Code:
    $('.fact').click(function() {
        var factboxid = $('.fact .factinfo').attr("id");
        $('#fact'+factboxid+' .factinfo').show();
    });
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 04-30-2009, 06:43 PM Re: jQuery: Show info box when clicked
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
Kinda there.

HTML Code:
	$('.fact').click(function() {
		$('.factinfo').hide();
		var thisid = $(this).attr("id");
		if(lastid == thisid) {
			$(this).find(".factinfo").show();
		}
		lastid = $(this).attr("id");
	});
However whenever I click on the info box it hides. Any suggestions?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Galaxian; 04-30-2009 at 06:45 PM..
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 04-30-2009, 06:55 PM Re: jQuery: Show info box when clicked
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
Fixed. Wrapped the text only in the div and heres the code:

HTML Code:
    $('.fact').click(function() {
        $('.factinfo').hide();
        var thisid = $(this).attr("id");
        if(lastid != thisid) {
            $(this).next(".factinfo").show();
            lastid = $(this).attr("id");
        } else {
            lastid = 0;
        }
    });
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 04-30-2009, 07:21 PM Re: jQuery: Show info box when clicked
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Glad you figured it out.

Just as a sidenote, don't feel like you always need to use jQuery methods:
Code:
var thisid = $(this).attr("id");
inside of the $.click() function could have easily been expressed as:
Code:
var thisid = this.id;
which is shorter and will parse faster.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to jQuery: Show info box when clicked
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14174 seconds with 12 queries