工作原型: 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