On Feb 13, 2007, at 11:22 AM, R. Rajesh Jeba Anbiah wrote:

For #1, what about:
$(document).ready(function() {
        $("#wrapper p").hide(); //hide initially
        $("#wrapper h2").click (function() {
                $("p", $(this).parent()).slideToggle("slow");
        });
});

Looks good to me. Also, instead of this...
$("p", $(this).parent()).slideToggle("slow");

...you could do this:
      $(this).siblings('p').slideToggle('slow');

If you still want to add all the css stuff in the jQuery code (I usually prefer adding and removing classes), you can do that in the same line by using the .filter() method:

$(document).ready(function() {
  $('#wrapper p').hide()
$('#wrapper h2').filter(':even').css('backgroundColor', '#ef0000').end().filter(':odd').css('backgroundColor', '#0000ef').end ().css({cursor: 'hand', cursor: 'pointer', color: '#fff'}).click (function() { $(this).siblings('p').slideToggle('slow'); });
});

Or, to make it more readable:

$(document).ready(function() {
  $('#wrapper p').hide()
  $('#wrapper h2')
  .filter(':even')
    .css('backgroundColor', '#ef0000')
  .end()
  .filter(':odd')
    .css('backgroundColor', '#0000ef')
  .end()
  .css({cursor: 'hand', cursor: 'pointer', color: '#fff'})
  .click(function() {
    $(this).siblings('p').slideToggle('slow');
  });
});


--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com





On Feb 13, 2:23 pm, "Dmitrii Dimandt" <[EMAIL PROTECTED]> wrote:
I've started collecting some examples I've come across while solving
problems using jQuery. I guess they could be interesting to the
community as a whole.

These (sort of) tricks are available here:http://dmitriid.com/ jquery/en/
  <snip>



--
  <?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com    Blog: http://rajeshanbiah.blogspot.com/


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to