I have a problem, my jQuery function doesn't work. It's initialize (alert before addEventListener works, but the click is not detected. The tricks works with a
onclick="attachEventsFid2()"
But not with my code :
function attachEventsFid2() {
var main=$('.main-wrapper');
var btn = document.getElementById("btn-iphone4");
btn.addEventListener('click', function(event) {
event.preventDefault();
$.ajax({
type:"post",
url:BASE_URL+'index/formfid2/',
data:{'iphone':iphone},
cache:false,
success:function(data){
main.parent().html(data);
}
});
});
};
Html part :
<div class="row row3">
<a id="btn-iphone5" class="ico-reserver choix-iphone" type="button" value="iphone5" ></a>
</div>
Logs :
Uncaught TypeError: Cannot read property 'addEventListener' of null
With getElementsByClassName i have an other log :
Uncaught TypeError: undefined is not a function (=>
btn.addEventListener('click', function(event) { ... )
Thanks !