-2

I create new element with js like this:

$("#vorschau_tr").append('<td><img src="bla.jpg" class="flipped js_is_a_broken_time_wasting_piece_of_garbage"></td>');

And try to just alert something like that:

$(".js_is_a_broken_time_wasting_piece_of_garbage").on({
    mouseover: function () {
        alert('enter');
    },
    mouseleave:function () {
        alert('leave');
    }
});

I know it was asked multiple times but every time it says the solution is to use on which I do but it's not working so how to do that?

$(".js_is_a_broken_time_wasting_piece_of_garbage").live( click, function(){
    alert('js_inventor_is_a_pos');
});

isn't working too

Eddy Unruh
  • 199
  • 3
  • 9
  • I've seen all that the solution is always using on ffs but it's not working – Eddy Unruh Apr 16 '18 at 08:39
  • The html you are appending to your row is invalid - you aren't closing your image src attribute. Check out this fiddle https://jsfiddle.net/ronuuhmf/2/ :) – 83N Apr 16 '18 at 09:19
  • Nope look the first answer, I accepted even though it's still not working with my code. JS just can't handle 3k lines of code because it's a POS – Eddy Unruh Apr 16 '18 at 09:23
  • I disagree - js is awesome - we run a SPA with >50k lines of code - and it works flawlessly and fast. The fiddle I attached works - so check your code before losing your temper as you've clearly done something wrong. – 83N Apr 16 '18 at 09:25
  • You don't know what you are talking about, I don't know how complex yout project with 50k code is, I'm sure it isn't. But I already did countless workarounds for js ILLOGICAL bs which you would never ever find in other programming languages like PHP and JAVA – Eddy Unruh Apr 16 '18 at 09:58
  • Yes, it is pretty complex. And it works. You shouldn’t need to use workarounds – you just need to write decent code. As per the accepted answer, and my fiddle, this does work - so if you are still having problems maybe post a more complete code sample or expand on where you are having issues instead of just slating the language. The issue isn’t javascript – it is clearly your understanding of it. – 83N Apr 16 '18 at 10:22

1 Answers1

1

You have missed closing " in img src="bla.jpg". That's why the selector is not working as expected:

$("#vorschau_tr").append('<td><img src="bla.jpg" class="flipped js_is_a_broken_time_wasting_piece_of_garbage"></td>');

$(".js_is_a_broken_time_wasting_piece_of_garbage").on({
    mouseover: function () {
        alert('enter');
    },
    mouseleave:function () {
        alert('leave');
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr id="vorschau_tr"></tr>
</table>
Mamun
  • 66,969
  • 9
  • 47
  • 59
  • Oh I just missed it here because I changed the generated image name to bla.jpg to keep it simple. The closing " is there in org code – Eddy Unruh Apr 16 '18 at 08:54
  • @EddyUnruh, Then there might be some other problem in your code, as you you can see it is working (in the answer snippet) as expected based on the code you have provided in the question..... thanks. – Mamun Apr 16 '18 at 09:04