views:

121

answers:

5

There is <dl> with padding-top

<dl id="posters" style="padding-top: 150px;">
<dt class="active">text</dt>
<dd class="active"><a href="#"><img width="150" height="150" src="..." /></a></dd>
<dt>text 2</dt>
<dd><a href="#"><img width="150" height="250" src="..." /></a></dd>
<dt>text 3</dt>
<dd><a href="#"><img width="150" height="350" src="..." /></a></dd>
</dl>

The difference between images - height.

Trying to write a script, which will change a height of the <dl>, when <dd> is clicked.

Height should be taken from the height attribute of the dd img.

Tryed this, but had no luck:

$("#posters dt").click(function(){
        var parent_padding = $("dd").find("img").height();
        $("dd").closest("dl").css("padding-top",parent_padding);
    }).andSelf().addClass("active")});

Thanks.

+3  A: 

Although your syntax is correct, trying to set a property can be set like this as well. .css(property, value);

Example

$(this).parent().css("padding-top", parent_padding);

$(this).css("color","red");

Reference and more examples: here

gmcalab
`css({"padding-top":parent_padding}` is valid, it can take more than one property: `css({"padding-top":parent_padding,color:'red'}`
Kobi
You're right, I just saw that. Thanks man!
gmcalab
doesn't work. Watched through firebug, seems that it cant catch the parent tag - <dl>
Happy
Where's the `<dd>` with the id of posters?
gmcalab
+1  A: 

Updated:

$("#posters dd").click(function(){
    var parent_padding = $(this).find("img").height();
    $(this).closest("dl").css("padding-top",parent_padding);
});
David Murdoch
So you you condemn my answer, then answer with the exact same thing. You're very sharp there chief.
gmcalab
@gmcalab. Sorry, but no. I changed `.attr("height")` to `.height()`.
David Murdoch
Wasn't talking about that line dude.
gmcalab
fixed the topic, it should catch 'dl parent', not an actual 'parent'.
Happy
@gmcaleb: You were suggesting that using `("property":"value"}` was causing a problem, which it was not. The reason I changed in my answer is because it is pointless to use the `{}` syntax when the `property, value` arguments work fine.
David Murdoch
@D M - Actually, I corrected myself saying the syntax is correct. But also provided the alternative `property,value` method. I know this method works fine, that's why I originally suggested trying it.
gmcalab
I deleted my comment since you corrected it you know...
David Murdoch
+5  A: 

Instead of getting the image's .attr('height') you can always just use the jQuery function .height().

Other than that, it should adjust your padding-top appropriately.

jsbin preview

gnarf
thats what I said and got voted down. +1 to you.
David Murdoch
@gnarf - No offense, but using `height()` was never a solution since the `height` attribute was explicitly set, and the OP was still having issues.
patrick dw
+1  A: 

In your HTML there's no element with the id posters, although that's what your selector is searching. Long shot, but maybe that's the problem? The rest of the code looks perfectly fine.

Max Shawabkeh
there is #posters, forgot to mention. Thanks.
Happy
+8  A: 
patrick dw
ok, thanks @patrick
Happy