<div class="post-story">
<div class="post-story-text">
<script>
$(document).ready(function(){
$(".more").click(function(){
var overvalue = $(".post-story-text").css("overflow-y");
if (overvalue=="hidden") {
$(".post-story-text").addClass("more-ex");
$(".post-story").addClass("more-story-ex");
}
else {
$(".post-story-text").removeClass("more-ex");
$(".post-story").removeClass("more-story-ex");
}
});
});
</script>
As HTC readied a new version of its flagship smartphone, it planned for many challenges. It didn't know that one of them would be Roshan Jamkatel, a teenager from Schaumburg, Ill.
This is true, but Tesla is more of a niche seller than a mass-market player. Which might be what HTC becomes if sales of its all-new phone don't set some all-new records.
<div class="more">....Continue Reading</div>
</div>
我正在研究显示不同帖子的元素,因为帖子很长,我包含了一个继续阅读的按钮,但问题是当我点击“...继续阅读”或(.more
) 所有 div 都展开,但我只想展开那个特定的 div。
最佳答案
你可以试试这个
$(document).ready(function () {
$(".more").click(function () {
var parent = $(this).closest('.post-story');
var overvalue = parent.find(".post-story-text").css("overflow-y");
if(overvalue == "hidden") {
parent.find(".post-story-text").addClass("more-ex");
parent.find(".post-story").addClass("more-story-ex");
} else {
parent.find(".post-story-text").removeClass("more-ex");
parent.find(".post-story").removeClass("more-story-ex");
}
});
});
关于javascript - 在点击事件上定位特定的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22938359/