0

I have a content div that I want to be set to specific height (50px) then onclick change to 'auto' - Can I make this work with jQuery? I have it in YUI see code below

 function toggleContent(p, showFull) {
    if (showFull) {
        YAHOO.util.Dom.setStyle(p, 'height', 'auto');
        p.setAttribute('onclick', "toggleContent(this, false);")
    } else {
        YAHOO.util.Dom.setStyle(p, 'height', '50px');
        p.setAttribute('onclick', "toggleContent(this, true);")
    }
    }

Here is an example of I want (YUI)

Joel
  • 467
  • 1
  • 6
  • 18
  • Possible duplicate of http://stackoverflow.com/questions/5003220/javascript-jquery-animate-to-auto-height – am_ Apr 11 '13 at 22:13

1 Answers1

1

Here's that code updated to use jQuery:

function toggleContent(p, showFull) {
    if (showFull) {
        $(p).height('auto');
        p.setAttribute('onclick', "toggleContent(this, false);")
    } else {
        $(p).height('50px');
        p.setAttribute('onclick', "toggleContent(this, true);")
    }
}

http://jsfiddle.net/ryanbrill/XUSdC/1/

ryanbrill
  • 1,981
  • 10
  • 13