QuackZilla QuackZilla - 5 months ago 25x
Javascript Question

How to change content in div on click?

Trying to change some content in divs on click. Found one solution, but it works only with ID. Change content of only one div. How to fix it?

$(document).ready(function () {
$("#buttons a").click(function() {
var id = $(this).attr("id");
$("#pages div").css("display", "none");
$("#pages div#" + id + "").css("display", "block");

Here is Jsfiddle

Edited Jsfiddle a little bit. Here is picture:

enter image description here


Not sure if I understand you correctly, but if you want to change the content of multiple div's, you can do it like this:


$(document).ready(function () {    
    $("button").click(function() {
        var content = $(this).data('content');   
        $('#pages .allowChange p').html(content);

Can you elaborate a bit more on your question if this is not what you are looking for?