javascript - Change div height to child div's height on click with JS -
i have div (divchatcontainer) top div (divchatcontainertop) have "span" element inside it. want container div resized "divchatcontainertop" height when "span" element clicked (ie: minimize chat window "divchatcontainertop" appears).
html code:
<div id="divchatcontainer" runat="server" style="overflow-y: scroll; box-sizing: border-box; word-wrap: break-word; width: 20%; max-height: 35%; position: fixed; right: 0px; bottom: 0%; box-sizing: border-box; background-color: #ebecef; border: solid #3a5896; border-width: 1px 0px 0px 1px; border-radius: 1px;"> <div id="divchatcontainertop" style="text-align: right; box-sizing: border-box; width: 100%; padding: 3px;"> <span style="float: left; box-sizing:border-box;width:50%;overflow:hidden;">left</span><span id="spanchatminimize" style="float: right">x</span> </div> </div>
external .js file:
document.getelementbyid('spanchatminimize').addeventlistener('click', function () { document.getelementbyid('divchatcontainer').style.height = document.getelementbyid('divchatcontainertop').style.height + 'px'; });
in debug notice it's not entering function. perhaps syntax of adding eventlistener wrong, or maybe "span" element have other name (on masterpage have "ctl00_elementname"), guess it's not case, container element statically in html outside contenplaceholder.
edit: following code works minimize
document.getelementbyid('spanchatminimize').addeventlistener('click', function () { document.getelementbyid('divchatcontainer').style.height = 10px; });
but following code don't nothing:
document.getelementbyid('spanchatminimize').addeventlistener('click', function () { document.getelementbyid('divchatcontainer').style.height = document.getelementbyid('spanchatminimize').style.height + 'px'; });
so assuming not being able "divchatcontainertop" or "span" height. can't screen height instead of height property?
it seems misunderstood question last night. if want height of div without setting height property in first place, should try 1 of:
document.getelementbyid('divchatcontainertop').clientheight document.getelementbyid('divchatcontainertop').offsetheight document.getelementbyid('divchatcontainertop').scrollheight
updated jsfiddle, logs 3 values , when click on span, height change.
reference:
Comments
Post a Comment