---
title: "problem in jQuery event not triggering"  
description: "problem in jQuery event not triggering"  
author: "Anonymous User"  
published: 2015-01-30  
updated: 2015-01-30  
canonical: https://www.mindstick.com/forum/12922/problem-in-jquery-event-not-triggering  
category: "asp.net"  
tags: ["jquery", "javascript"]  
reading_time: 1 minute  

---

# problem in jQuery event not triggering

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [trigger](https://www.mindstick.com/blog/167/triggers-in-wpf) a post [request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php) when a [user clicks](https://answers.mindstick.com/qa/34556/if-a-user-clicks-all-the-google-ads-on-my-site-is-it-foul) the [submit button](https://www.mindstick.com/forum/12834/make-text-appear-when-submit-button-clicked-and-checkbox-is-unchecked) for a comment. [Right now](https://answers.mindstick.com/qa/36863/what-would-happen-if-gravity-became-5-percent-stronger-right-now) clicking the submit button [triggers](https://www.mindstick.com/articles/337000/what-are-sql-triggers-and-ways-of-using-them-effectively) nothing, I even tried to console.log($(this)) I got no output. The first code below is the jQuery event code and ajax code. The block of code below that is the html button. thanks for the help.

```
 $('#submitComment').on('click', '#content', function() {        $.ajax({            url: 'http://localhost:3000/comments',            type: 'POST',            data: data = { comment: {                body: $(this).find('input[name="createComment"]').val(),                user_id: 1,                image_set_id: 2}            }        }).done(function(response) {            console.log(response);        });    });
```

the button I am trying to [target](https://yourviews.mindstick.com/view/81207/small-industries-should-be-the-target-of-economic-relief-package) with jQuery event

```
<div class="container">    <div id="content">      //the code between comments is in a Handelbar template        <input name="createComment">        <button type="submit" id="submitComment">Create Comment</button>       //end of handelbar template    </div> </div>
```

## Replies

### Reply by Anonymous User

You need to bind the delegated handler to an ancestor(#content) of the target element(submitComment)\

```
$('#content').on('click', '#submitComment', function () {    $.ajax({        url: 'http://localhost:3000/comments',        type: 'POST',        data: data = {            comment: {                body:$(this).find('input[name="createComment"]').val(),               
user_id: 1,               
image_set_id: 2            }        }    }).done(function (response)
{        console.log(response);    });});
```


---

Original Source: https://www.mindstick.com/forum/12922/problem-in-jquery-event-not-triggering

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
