JavaScript Register an event handler for a CSS class using jQuery does not work when elements are added dynamically register event handler javascript,register event handler c#,register event

As written your code works. So there must be another reason for it not working.

Either the DOM isn't ready in which case wrap the click handler in the DOM ready callback

$(function(){
 // register event handler for delcomment
 $( "span.delcomment" ).click(function() {
  // some code that actually deletes comment from database
 });
});

Or these elements are being added dynamically, in which case you would delegate the click event to that specific class

// register event handler for delcomment
$( "body" ).on("click", "span.delcomment", function() {
 // some code that actually deletes comment from database
});

This delegation works by assigning a handler to the body element itself, and then every time a click event is registered, it looks to see if the target element matches the given selector. If it does, then the callback function is called (and internally .bind is used to make that target element equal to this in the callback).

Answer:1

I have created two functions that run a similar set of IF statements, one shows the cost of a game, the other its name. I have used "onclick" to display both values in my form. It all works but ...

I have created two functions that run a similar set of IF statements, one shows the cost of a game, the other its name. I have used "onclick" to display both values in my form. It all works but ...

I'm new to Mocha and I'm trying to run the tests on this code: "use strict"; process.env.NODE_ENV = 'test'; var assert = require('assert'), Browser = require('zombie'), xapp = require('../...

I'm new to Mocha and I'm trying to run the tests on this code: "use strict"; process.env.NODE_ENV = 'test'; var assert = require('assert'), Browser = require('zombie'), xapp = require('../...

I've been trying to push a complex json data record into a json variable. This is the code I tried to do so. var marks=[]; var studentData="student1":[{ "term1":[ {"LifeSkills":[{...

I've been trying to push a complex json data record into a json variable. This is the code I tried to do so. var marks=[]; var studentData="student1":[{ "term1":[ {"LifeSkills":[{...

Can I center the content of div with center-block?? The following example does not work: <div class="form-group"> <div class="center-block"> <input id="...

Can I center the content of div with center-block?? The following example does not work: <div class="form-group"> <div class="center-block"> <input id="...

  1. center content with flexbox
  2. center content with css
  3. center content with flex
  4. center content with padding
  5. center content with bootstrap
  6. center content with margin
  7. center content with css grid
  8. flexbox center content
  9. center content with html
  10. center content in div
  11. center content in div bootstrap
  12. center content in div css
  13. center content in div vertically
  14. center content in div bootstrap 4
  15. center content in column bootstrap
  16. center content in td
  17. center content in column bootstrap 4
  18. center content in table cell
  19. center content in div horizontally
  20. center content in row bootstrap 4