Shniper
Shniper

Reputation: 854

How to empty() on click with jquery

I need to empty an h2 element when a button is clicked. I do this in part of my code already and it works fine, but when I try to empty this part of my code it doesn't work. I can't figure out why.

JSFiddle link here

 $('#help').click(function() {
    $('#intro').empty();
    $('#intro').text("News:");
    $('#help').hide();
    $('#noHelp').hide();
    $('#news').text("Battle system created");
   });

This part is breaking it and I don't know why

var fly = new Monster("fly", 1, 1, 5, 2, 1, 1);
var mouse = new Monster("mouse", 2, 3, 10, 2, 1, 2);
var rat = new Monster("rat", 4, 5, 20, 4, 2, 2);
var rabidChihuahua = new Monster("chihuahua", 6, 8, 35, 6, 1, 4);
var bulldog = new Monster("bulldog", 10, 14, 60, 10, 4, 1);
var wolf = new Monster("Wolf", 15, 18, 65, 12, 3, 6);
var vampie = new Monster("Vampire", 20, 23, 100, 12, 5, 4);
var werewolf = new Monster("Werewolf", 25, 29, 100, 14, 3, 9);
var giantSlime = new Monster("Giant Slime", 31, 38, 200, 7, 15, 1);
var babyDragon = new Monster("Baby Dragon", 39, 50, 150, 16, 9, 5);
var orc = new Monster("Orc", 50, 64, 220, 10, 12, 4);
var succubi = new Monster("Succubi", 61, 80, 190, 21, 8, 12);
var elderDragon = new Monster("Elder Dragon", 75, 100, 300, 21, 15, 8);
var sanaan = new Monster("Sanaan", 150, 500, 500, 55, 45, 30);

Upvotes: 0

Views: 226

Answers (1)

Nutshell
Nutshell

Reputation: 8537

I've updated your fiddle :

see here

I've changed this line to test the opt var :

if(opt.length > 0){
    monsterList.appendChild(opt); // appending option to select element
} 

Upvotes: 2

Related Questions