0

Here's what I am trying to do in (jquery,html):

The aim is to make it so that when I hit the switch (basic/advanced) a block of html is added to the existing html. Within this new block there will be another switch (less/more) which should added another block.

However I can't seem to (less/more) switch to work. In fact the function is not running at all.

The function that corresponds to the (basic/advanced) switch is:

var selectInvestment = "basic";
function expandInvestment(){
    $("input[type=radio][name=expandInformation]").click(function(){
        selectInvestment = $(this).val();
       var huge = 'huge block of html code in here';
        if(selectInvestment == "advanced"){
            $('.investmentBlock').empty();
            $('.investmentBlock').append(huge);
            expandedExpenses();
        } else if(selectInvestment == "basic"){
            $('.investmentBlock').replaceWith("<...more html code...>");
        }
    });
}

And it's similar for the less/more switch.

Here is jsfiddle preview. http://jsfiddle.net/1g6uraht/1/

Youbloodywombat
  • 2,087
  • 2
  • 13
  • 10

1 Answers1

1

Because you're dynamically adding your new radio buttons, you'll need to use on

$("input[type=radio][name=expandedExpenses]").click(function(){

becomes

$("document").on('click', 'input[type=radio][name=expandedExpenses]', function(){

see jquery on

Jason
  • 734
  • 1
  • 7
  • 17