execute a script by pressing a button with date attribute

0

I made an html form, put it on a platform that loads this form. But there are buttons on the platform that execute functions in the form (like send the form, save and etc). Here I found that I can manipulate these platform buttons with codes inside the form using this:

window.parent

For example, I can drop an alert when a certain button on the platform is pressed with this code:

window.parent.$(".fixedTopBar").find("button").on("click", function(ev) { alert("OK"); });

I have this button (which logically I can not change it since it is from the platform):

<button type="button" class="btn btn-primary" data-send="">Enviar</button>

And I want to run a script when it is pressed ... As I have other buttons on the page, I decided to capture the "on (click)" button with the data-send (since it is unique in that) p>

I've tried codes like:

window.parent.$('[data-send]').on("click", function(ev) { alert("OK"); ); 

window.parent.$('button[data-send]').on("click", function(ev) { alert("OK"); );    

window.parent.$('button').data("send").on("click", function(ev) { alert("OK"); }); 

But it did not work. I do not understand much about the date attribute ... It should be from there the difficulty of understanding how to use it.

If it is better, I drew it as it is: [Red] Environment [Blue] form [Green Arrow] Button I want to capture the click

    
asked by anonymous 12.04.2017 / 14:55

1 answer

0

Problem solved. First I had to make a change: instead of using the select button, I used the data-send attribute, because there is another element in the environment that sends (and also has the same data-send attribute) but there is no button. That is, from this code:

$('button[data-send]')

I went to this code:

$("[data-send]")

So the script covers both cases.

About this question code does not work:

window.parent.$('[data-send]').on("click", function(ev) { alert("OK"); );

It works normally, there must have been some problem (or platform, or cache or even some missing quotes or dot) and when I ran I thought it did not work.

    
12.04.2017 / 19:15