jquery: how to get different content with different button click? -
i'm new jquery, , i'm trying implement multiple buttons same modal (bootstrap), display relevant content different button click.
i have following code:
$(".demo").click(function (){ var demo2title = "title 2"; var demo1title = "title 1"; var demoid = $(this).attr("id"); var demotitle = demoid.concat("title"); $(".title").html(demotitle); }); demotitle suppose concatenate clicked element , merge "title", create e.g.: demo2 + title = demo2title. , .html(demotitle) suppose display var object (demo2title). displays "demo2title" title, instead of "title 2"...
what can do? thanks!
demo1title , demo2title variables, whereas value of demotitle string. .html(demotitle) going set html content of string value, not value of variable same name string.
the way access identifier string via [] properties. example:
var titlesbyid = { demo1: 'title 1', demo2: 'title 2' }; $(".demo").click(function (){ var demoid = $(this).attr("id"); var demotitle = titlesbyid[demoid]; $(".title").html(demotitle); });
Comments
Post a Comment