0

I have written a click function on the HTML page for DIV elements. But after using jQuery load(), that click function for the DIV elements does not work. For example:

$(".about .visible").click(function () {
$("form").toggleSlide();
});
<div class="mypro"> 
<div class="about">
<div class="visible"></div>
here is my text
</div>
</div>

If I use:

$(".mypro").load("get.php");

Actually this is the original code:

$('.cv-right .cv-right-content .about').on({
mouseenter: function (a) {
     $(this).find('.about .visible').show();
},
mouseleave: function (a) {
    $(this).find('.about .visible').hide();
}

});

Then, jQuery code for .about .visible click will not work. How can I solve this problem?

Javid Karimov
  • 435
  • 5
  • 22
  • The load tag is not for the kind of load you are discussing here. Please always read tag descriptions to see if they are appropriate before you add them. – Anders Sep 30 '15 at 13:55

1 Answers1

3

You should delegate event to handle dynamic elements:

$(".mypro").on("click", ".about .visible", function () {
    $("form").toggleSlide();
});
A. Wolff
  • 74,033
  • 9
  • 94
  • 155
  • $(".about").on({ mouseenter: function () { $(".visible",this).show(); }, mouseleave: function () { $(".visible",this).hide(); } }); – Javid Karimov Sep 30 '15 at 13:25
  • Describe not working. Error in console or what happen? BTW, what means your first comment here? – A. Wolff Sep 30 '15 at 13:26
  • It is like jquery breaks. every jquery code till this div(div .about) works. but after this div does not work when I load("get.php") – Javid Karimov Sep 30 '15 at 13:27
  • You have to debug it. If any js stop working, i guess you have one or more unhandled exception – A. Wolff Sep 30 '15 at 13:28
  • Ok, and how can I do it ? Is there any example or document ? – Javid Karimov Sep 30 '15 at 13:30
  • If you are completly new in browser developement, then see: http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code Otherwise i'm sorry, i didn't understand what you meant – A. Wolff Sep 30 '15 at 13:32
  • please, can you give example for unhandled exception ? – Javid Karimov Sep 30 '15 at 13:54
  • No, i cannot give you example of unhandled exception... Open your console and see if there is error. – A. Wolff Sep 30 '15 at 14:02
  • I looked everything, but could not find anything. console did not give any error. may be I have to put the whole code here ? – Javid Karimov Sep 30 '15 at 18:32
  • I found, I used $(document). But there is another problem. when I click submit button inside .about the second time it goes to the action file. But it must not do it – Javid Karimov Sep 30 '15 at 21:04
  • I think you are binding submit event and preventing default behaviour. If ya, you have to delegate submit event too. – A. Wolff Oct 01 '15 at 07:17
  • Aha, I understand. Thank you for help, if there will be any other problem (possibly will be). I will write here – Javid Karimov Oct 01 '15 at 07:46
  • @CavidKərimov No, for other issue, please consider to ask a new specific question – A. Wolff Oct 01 '15 at 07:59