简体   繁体   English

如果DIV具有与ATTRUBUTE相同的CLASS,则单击它可以显示DIV的内容

[英]Show content of DIV by clicking on it if it has the same CLASS as ATTRUBUTE

What I am trying to achieve is: I have a few groups of DIVs with attribute 'rel' (dynamically created) and a DIV inside with the same class as the parents attribute. 我要实现的目标是:我有几组具有“ rel”属性(动态创建)的DIV,并且内部具有与Parents属性相同的类的DIV。

<div class="quote-logos logo-94" rel="quote-94">
<div id="quote-94" style="display:none;">
    <div class="quote">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
    <div class="author-name">-1</div>
</div>
</div>
 <div class="quote-logos logo-169" rel="quote-169">
<div id="quote-169" style="display:none;">
    <div class="quote">
        <p>Duis turpis tellus, porta vitae arcu ut, aliquet volutpat turpis.</p>
    </div>
    <div class="author-name">-2</div>
</div>

By clicking on the main DIV I want to add its content to the separate DIV. 通过单击主DIV,我要将其内容添加到单独的DIV中。

 <div id="display"></div>

I have managed to get the attribute and alert it but cannot make the content of the parent DIV after click on it appended to 我已经设法获取属性并对其发出警报,但是单击后将其添加到父DIV的内容后无法

Can anyone please help? 谁能帮忙吗? My fiddle is available below: 我的小提琴可在下面找到:

http://jsfiddle.net/KSaGe/2/ http://jsfiddle.net/KSaGe/2/

Please feel free to amend it... Note the attributes are dynamically created... 请随时对其进行修改...请注意,属性是动态创建的...

Does this do what you're looking for? 这是您要找的吗? http://jsfiddle.net/KSaGe/2/ http://jsfiddle.net/KSaGe/2/

 $('.quote-logos').click(function () {
     $("#display").text($(this).find("p").text());
})

http://jsfiddle.net/KSaGe/5/ http://jsfiddle.net/KSaGe/5/

$('.quote-logos').click(function () {
     $("#display").html($(this).find('#' + $(this).attr('rel')).html());
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM