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';
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745228371a4617567.html
评论列表(0条)