Neela Neela - 1 year ago 53
jQuery Question

How to get form element seen in DOM and not in source code?

We are using the marketo form on one of our Drupal installation and I am trying to add a on click event when the button is clicked. But when I view the source I cannot see the from element . I can see it on the DOM inspector however.

This is what I see on the view source.

<form class="marketo-form-wrapper"

The inspect element screenshot is attached.

No matter what I do I cannot call the click function when the submit button is clicked.
I could do upto this point

$('.marketo-form-wrapper').click(function (e) {

I dont want this function to be called when user clicks on the form wrapper. I want it to be called when the actual button is clicked.

If I do this nothing shows up.

$('.marketo-form-wrapper .mktoButtonRow:button').click(function (e) {


Answer Source

Use the delegate selector.


This will apply a click handler to any element with the .mktoButton class, inside the .marketo-form-wrapper class, added after the DOM has loaded. Which is the case in your question.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download