Dexter Schneider
Dexter Schneider

Reputation: 2520

How to hide div on click and change html in another

I have a simple request(still learning javascript). I have a title div and 3 divs(with an anchor tag inside each) below it. 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. How can I do that? See overly simplified example.

Upvotes: 0

Views: 359

Answers (3)

Priyank Patel
Priyank Patel

Reputation: 6996

Not sure as to this is what you are looking for Check demo.

You are mixing javascript with jquery. You can hide a element by something like this

$(this).hide();

Upvotes: 1

Lusitanian
Lusitanian

Reputation: 11132

You're mixing jQuery DOM access and plain DOM access, which will cause some problems. Use the $('#id') selector instead of document.getElementById('blah');

To make a div disappear on click:

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

Upvotes: 1

Zoltan Toth
Zoltan Toth

Reputation: 47677

Try this - http://jsfiddle.net/gGAW5/54/

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

Upvotes: 1

Related Questions