0

What i want is, when click on (X) inside a button, then it should trigger the respective callback registered. But i dont know why it is failing. Below is what i tried:

HTML

<div id="cover"></div>
<template id='filtertemp'>
                <button id="filtype" class='filbut' data-filter=""></button>
</template>
<button id='create' onclick="filter();">Click</button>

JQUERY

function filter(){
var content= $('#filtertemp')[0].content;
if(content){
    var filType= content.querySelector('#filtype');
    $(filType).text("type : sometype");
    var clone= document.importNode(content,true);
    $('#cover').append($(clone));
    $('#cover > .filbut:last-child').append('<span class="glyphicon glyphicon glyphicon-remove"></span>');
}
$('.glyphicon').on('click', function(){
    alert('Remove');
});
}

Here is the fiddle link: http://jsfiddle.net/wtce6dje/

I tried even below to register listener, but that too dint seemed to work:

$('body').on('click','.glyphicon', function(){
    alert('Remove');
});
Siguza
  • 21,155
  • 6
  • 52
  • 89

2 Answers2

2
<button id='create' Onclick="return filter();">Click</button>
Ram G Athreya
  • 4,892
  • 6
  • 25
  • 57
Hemanth M C
  • 436
  • 1
  • 4
  • 18
0

having a click event within a button works for me in Chrome, but doesn't in the other browsers that I have tested.

It works when it's swapped out with a div:

<template id='filtertemp'>
    <div id="filtype" class='filbut' data-filter=""></div>
</template>
Shameen
  • 2,656
  • 1
  • 14
  • 21