Ivana
Ivana

Reputation: 13

Toggle div visibility problem

How onclick some button, id=i_1, to toggle visibility of some div with id=d_1 (to show slide right while appearing)? I need to use JQuery for this.

Upvotes: 0

Views: 142

Answers (2)

Joseph Marikle
Joseph Marikle

Reputation: 78520

The devious side of me wanted to code this dynamically

http://fiddle.jshell.net/Vcyj8/1

HTML

<input type="button" value="button 1" id="i_1"/><br>
<div id="d_1">div 1 text description</div>
<input type="button" value="button 2" id="i_2"/><br>
<div id="d_2">div 2 text description</div>
<input type="button" value="button 3" id="i_3"/><br>
<div id="d_3">div 3 text description</div>
<input type="button" value="button 4" id="i_4"/><br>
<div id="d_4">div 4 text description</div>

CSS

div {
  display:none;   
}

input {
  padding:5px;   
}

jQuery

$("[id^='i_']").click(function(){

  $("#d_"+this.id.substr(2)).slideToggle("fast");

})

Upvotes: 0

James Allardice
James Allardice

Reputation: 165941

It's difficult to understand exactly what you're after from your question, but perhaps something like this will get you started:

$("#i_1").click(function() {
    $("#d_1").animate({ width:'toggle' }, 500);
});

Here's an example showing that in action.

If you add some more information and some sample code to your question, it will be easier to provide a more accurate answer!

Upvotes: 1

Related Questions