admin管理员组文章数量:1415139
Geniuses, Is this possible? Please help as my jQuery javascripting is bad.
I need to get the height of a div, which is dynamically created (so has auto height by default) - the dynamic tweet content is also generated by javascript, which I hope isnt causing issues.
See my dynamic div...
<div id="tweet-area"></div>
I then need to plant the div#tweet-area height into the script below...
$("#sidebar-wrapper").css({ bottom: " + variable here + " });
So this was my attempt, but not its quite working...
var tweetheight = document.getElementById('tweet-area').offsetHeight;
$("#sidebar-wrapper").css({ bottom: " + tweetheight + " });
Any advice would be hugely helpful thanks.
Josh
UPDATE
This is the script that works - loaded after the tweet script
var tweetheight = $("#tweet-area").height();
$("#sidebar-wrapper").css({ bottom: tweetheight});
Thank you all!
Geniuses, Is this possible? Please help as my jQuery javascripting is bad.
I need to get the height of a div, which is dynamically created (so has auto height by default) - the dynamic tweet content is also generated by javascript, which I hope isnt causing issues.
See my dynamic div...
<div id="tweet-area"></div>
I then need to plant the div#tweet-area height into the script below...
$("#sidebar-wrapper").css({ bottom: " + variable here + " });
So this was my attempt, but not its quite working...
var tweetheight = document.getElementById('tweet-area').offsetHeight;
$("#sidebar-wrapper").css({ bottom: " + tweetheight + " });
Any advice would be hugely helpful thanks.
Josh
UPDATE
This is the script that works - loaded after the tweet script
var tweetheight = $("#tweet-area").height();
$("#sidebar-wrapper").css({ bottom: tweetheight});
Thank you all!
Share Improve this question edited Nov 17, 2011 at 14:40 Joshc asked Nov 17, 2011 at 14:20 JoshcJoshc 3,86316 gold badges81 silver badges125 bronze badges 5-
1
$( '#sidebar-wrapper' ).css({ bottom: $( '#tweet-area' ).height() });
– Šime Vidas Commented Nov 17, 2011 at 14:22 - it's not working still? Though I didnt know you could write it that short. I can see it should work. – Joshc Commented Nov 17, 2011 at 14:26
- Also notice that you should run it after your #tweet-area has been populated (with tweets). – Stefan Commented Nov 17, 2011 at 14:28
- Do you execute this AFTER the tweet-area has been added to the DOM? Also are the tweet inside the tweet-area float: left (or right?) If they are you'll need to do a clearfix. You may need to do one anyway. – kasdega Commented Nov 17, 2011 at 14:30
- It works thanks - I added the script after the tweet area has been added to the DOM. Thanks for all the helpful advice! – Joshc Commented Nov 17, 2011 at 14:39
2 Answers
Reset to default 2maybe $("#sidebar-wrapper").css("bottom", tweetheight);
would do it?
var tweetheight = $("#tweet-area").height();
Has worked for me in getting the height of an element ^
Why are you putting a variable name in quotes? That makes it a string. Try this:
var tweetheight = document.getElementById('tweet-area').offsetHeight;
$("#sidebar-wrapper").css({ bottom: tweetheight});
I'd remend not using jQuery unless necessary, though. The CSS properties could easily be changed without jQuery like this:
document.getElementById('sidebar-wrapper').style.bottom = tweetheight + 'px';
本文标签: javascriptGet variable div height and plant var into another css selectorStack Overflow
版权声明:本文标题:javascript - Get variable div height and plant var into another css selector - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745228371a2648713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论