工作原型: http://jsfiddle.net/ad5qa/K5fdZ/28/jQuery的擴大DIV父innerHTML的高度
因爲當更多的按鈕被點擊的parentsUntil被抓在頁面的所有div某種原因。我只是想獲得div.htmlbox並有高度自動,所以我可以看到完整的內容。然後點擊減少將其縮小回50px高度。任何幫助將不勝感激。
$('.morebox a').toggle(function() {
var $this = $(this);
var $parent =$this.parentsUntil('.htmlbox');
$parent.height('auto')
$this.text('less')
$parent.css('border', '2px solid magenta')
$this.css('border', '2px solid red')
}, function() {
$parent.height('50px')
$this.text('more')
});
<h3>Description</h3>
<div class="htmlbox">
This is a samle description that goes here with short or long content in this panel. If the text is higher than 50px then it should be hidden by the box. You must click expand to view the remaining content in the html box div. The float box is used to cut off the overflow of the content.
<div class="fade-overlay"></div>
</div>
<div class="morebox">
<img align="absmiddle" alt="more-less grabber" src="http://goo.gl/ho277">
<a href="#" style="line-height: 10px">more</a>
<img align="absmiddle" alt="more-less grabber" src="http://goo.gl/ho277">
</div>
請總是直接包含在你的問題相關的代碼。如果jsfiddle不復存在,這個問題應該仍然對其他人有用。 –
根據你的HTML,似乎'.htmlbox'是'.morebox'的父親。例如,'.htmlbox'是'fade-overlay'的父級,但與'.morebox'的級別相同。 – Chase