Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jQuery toggle question

Status
Not open for further replies.

DarrenPower

IS-IT--Management
Nov 1, 2001
56
GB
Hi,

I wonder if you can help me. I have a right hand column with an image in the background, and questions in the left hand column.

Next to the questions are icons which, when clicked, bring up help text in the right column and hide the column's background image.

If they click on the help text or the icon, then the text disappears, but the background image of the column does not reappear, unsurprisingly.

I'm currently using jQuery toggle.

Is there a way of ensuring that the background image displays when the help test is off? I tried using toggle for the background image also, but if you clicked on the help text for a different question, both would appear and affect layout.

e.g. (.d2a-info is the background image)

$(document).ready(function() {
$('a.showhidecontact, .contact').click( function() {
$('.name').hide();
$('.contact').toggle();
$('.security').hide();
$('.address').hide();
$('.d2a-info').hide();
return false;
});

});
 
Hi,

I've made a fist of packaging it up to show you what I mean (as it's a .net app not publically available as yet). The bits to look for in the css are:

# Direct to App Navigation and Column

and

# Help Column

Please let me know if anything's unclear as it's quite messy!

Kind regards,

Darren.
 
 http://www.box.net/shared/nxcrv58arb
Hi

That code looks quite bad. I would write it like this :
Code:
[b]var[/b] helpnow[teal]=[/teal][green][i]''[/i][/green]

[b]function[/b] [COLOR=darkgoldenrod]ch[/color][teal]([/teal]what[teal])[/teal]
[teal]{[/teal]
  $[teal]([/teal][green][i]'.name'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]hide[/color][teal]()[/teal]
  $[teal]([/teal][green][i]'.contact'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]hide[/color][teal]()[/teal]
  $[teal]([/teal][green][i]'.security'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]hide[/color][teal]()[/teal]
  $[teal]([/teal][green][i]'.address'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]hide[/color][teal]()[/teal]
  $[teal]([/teal][green][i]'.d2a-info'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]show[/color][teal]()[/teal]

  [b]if[/b] [teal]([/teal]what [teal]&&[/teal] helpnow[teal]!=[/teal]what[teal])[/teal] [teal]{[/teal]
    $[teal]([/teal][green][i]'.'[/i][/green][teal]+[/teal]what[teal]).[/teal][COLOR=darkgoldenrod]show[/color][teal]()[/teal]
    $[teal]([/teal][green][i]'.d2a-info'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]hide[/color][teal]()[/teal]
    helpnow[teal]=[/teal]what
  [teal]}[/teal] [b]else[/b] helpnow[teal]=[/teal][green][i]''[/i][/green]
[teal]}[/teal]

$[teal]([/teal]document[teal]).[/teal][COLOR=darkgoldenrod]ready[/color][teal]([/teal][b]function[/b][teal]()[/teal] [teal]{[/teal]
  $[teal]([/teal][green][i]'a.showhidename'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]click[/color][teal]([/teal][b]function[/b][teal]()[/teal][teal]{[/teal][COLOR=darkgoldenrod]ch[/color][teal]([/teal][green][i]'name'[/i][/green][teal])[/teal][teal]}[/teal][teal])[/teal]
  $[teal]([/teal][green][i]'a.showhidecontact'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]click[/color][teal]([/teal][b]function[/b][teal]()[/teal] [teal]{[/teal][COLOR=darkgoldenrod]ch[/color][teal]([/teal][green][i]'contact'[/i][/green][teal])[/teal][teal]}[/teal][teal])[/teal]
  $[teal]([/teal][green][i]'a.showhidesecurity'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]click[/color][teal]([/teal][b]function[/b][teal]()[/teal] [teal]{[/teal][COLOR=darkgoldenrod]ch[/color][teal]([/teal][green][i]'security'[/i][/green][teal])[/teal][teal]}[/teal][teal])[/teal]
  $[teal]([/teal][green][i]'a.showhideaddress'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]click[/color][teal]([/teal][b]function[/b][teal]()[/teal] [teal]{[/teal][COLOR=darkgoldenrod]ch[/color][teal]([/teal][green][i]'address'[/i][/green][teal])[/teal][teal]}[/teal][teal])[/teal]
  $[teal]([/teal][green][i]'.name, .contact, .security, .address'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]click[/color][teal]([/teal][b]function[/b][teal]()[/teal] [teal]{[/teal][COLOR=darkgoldenrod]ch[/color][teal]()[/teal][teal]}[/teal][teal])[/teal]
  [COLOR=darkgoldenrod]ch[/color][teal]()[/teal]
[teal]}[/teal][teal])[/teal]
Note that I not know jQuery, so the above code probably could be optimized and/or beautified.

By the way, do not specify the [tt]javascript:[/tt] pseudo-protocol in event attributes.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top