How to dynamically add a click handler to an li with jQuery -


i'm trying add click handler li added dom through jquery. thought way did it:

jquery('.deleteupload').on('click', '.deleteupload', function() {     var strdocid = jquery(this).prop('id');     //if (confirm('are sure want delete resource') == true) {         $.post('/study-clubs/meetings/delete-upload', {strdocid : strdocid},             function(objdata){                 console.log(objdata);             }         );         jquery('li#' + strdocid).remove();     //}      return false; }); 

here markup:

<li class="pdf deleteli" id="<?php echo $this->escape($this->objdocrow->id); ?>">    <label><input type="radio" name="documents[1]" value="0" /> pre-meeting</label> &nbsp;    <label><input type="radio" name="documents[1]" value="1" /> post-meeting</label> &nbsp;    <label><input type="radio" name="documents[1]" value="2" checked /> not use</label> &nbsp;    <a href="#" class="deleteupload" id="2">delete</a> &nbsp;    <a href="/..."><?php echo substr($this->escape($this->objdocrow->doc_title), 0, -4); ?></a> </li> 

i want delete li when click on a tag class of deleteupload. doing wrong? when click on it, i'm taken top of page. tried deleteli instead of deleteupload in jquery, didn't work either.

try changing first line to:

jquery('.deleteli').on('click', '.deleteupload', function() { 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -