简体   繁体   English

如何在单击时隐藏div并在另一个中更改html

[英]How to hide div on click and change html in another

I have a simple request(still learning javascript). 我有一个简单的请求(仍在学习javascript)。 I have a title div and 3 divs(with an anchor tag inside each) below it. 我下面有一个标题div和3个div(每个内部都有一个锚标记)。 Basically what I want, is when you click on one of the anchor tags, that that specific anchor tag should hide(actually its parent div), and the text in the Title div above should change. 基本上我想要的是,当您单击某个锚标记时,该特定的锚标记应隐藏(实际上是其父div),并且上面的Title div中的文本应更改。 How can I do that? 我怎样才能做到这一点? See overly simplified example . 参见过度简化的示例

Try this - http://jsfiddle.net/gGAW5/54/ 试试这个-http://jsfiddle.net/gGAW5/54/

$(document).ready(function() {
    $("a").click(function() {
        $("#myTitle").html( $(this).html() );
        $(this).hide();
    });
});

You're mixing jQuery DOM access and plain DOM access, which will cause some problems. 您正在混合使用jQuery DOM访问和纯DOM访问,这将引起一些问题。 Use the $('#id') selector instead of document.getElementById('blah'); 使用$('#id')选择器代替document.getElementById('blah');

To make a div disappear on click: 要使div在单击时消失:

$('#mydiv').click(
    function()
    {
        $(this).hide();
        $('#otherdiv').html('new html');
    }
);

Not sure as to this is what you are looking for Check demo . 不确定这是您在寻找Check demo的内容

You are mixing javascript with jquery. 您正在将JavaScript与jquery混合使用。 You can hide a element by something like this 您可以通过这样的方式隐藏元素

$(this).hide();

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

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