Answer the question
In order to leave comments, you need to log in
How to add an event to a form that is in js and not html?
Hello
There is a simple landing page
, you need to set a Yandex goal on button click
, the form is written using js, from which I know only alert ()
<form id="form" action="">
<input type="text" name="name" placeholder="Ваше имя">
<input type="text" name="tel" placeholder="Ваш номер телефона">
<div class="form_bottom">
Заказать звонок <!--кнопка-->
</div>
</form>
onclick="yaCounterXXXXXX.reachGoal('zakazatZvonok'); return true;"
obviously it doesn’t give anything Answer the question
In order to leave comments, you need to log in
If you need to hang an event on any element in js, you first need to make this very element and then insert data (Markup) into it, for example:
var myBtn = '<button id="btn"> click it </button>';
var myElement = document.createElement('div');
myElement.innerHTML = myBtn ;
var fooBtn = myElement.getElementById('btn');
fooBtn.addEventListener('click', function(){
alert();
})
myForm.querySelector('form_bottom');
myDiv.find('button').on('click', function(){
alert();
});
var myDiv = document.createElement('div');
myDiv.append('button');
$(myDiv).on('click', function(){
alert();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question