7
I have a code jQuery that generates a div it works smoothly, in it I have the following excerpt
div += "<p>Coloque o seu <a class='text-orange' id='link_new_ad'>veículo a disposição</a>!</p>";
then I add this div and it appears on the right screen, but my problem is that I wanted to call the event another button by clicking this link
$("#link_new_ad").click(function (){
alert('teste');
$("#bundle_ad_submit").trigger('click');
});
however when I click on the link nothing happens, if you put the link in html instead of put by append(div) it calls the event.
Somebody knows what’s going on, it’s better to fix it?
Bro may believe what you said, but for some reason it didn’t work out the @pedro-camara-junior response worked.
– Marcius Leandro
Rodrigo, I did a test with
on
directly in the browser console but could not make it work, can post an example maybe?– Pedro Camara Junior
@Rodrigo, you’re applying the event
on()
in an element that does not yet exist, this will not monitor the inclusion of the same.– Tobias Mesquita
There is another syntax, try $('body'). on("click", "your element", Function() {})
– Rodrigo Mello
http://api.jquery.com/on/
– Rodrigo Mello
Using your JS before or after the body can also influence... It is recommended to use JS before closing the body.
– Rodrigo Mello
@Rodrigomello, this was a recommendation given by Yahoo in the early days of the internet. Today it is interesting to use <src="file.js" script />
– Tobias Mesquita