javascript - click event is not working while onclick is working -


I have implemented click event on an IMG tag in my code and it is not working at all, but when I Applying the same code onclick on the same tag started to work perfectly. The following is the code: -

  // Click on the IIG to stop the disabling $ ('Img.close_url') (function () {warning ('off'); $ (' $ ('Input # hidden_is_url') Val (); $ ('Input # hidden_url_content'). Val (0);} Hide ($) ($ input 'hidden_rill_title'). Val (); $ ('Input # hidden_url_content'). ); // close the img tag function closeUrl () {$ ('div.urlResult') onclick to close the div. Hide (); . $ ('Input # hidden_url_title') val (); . $ ('Input # hidden_url_content') val (); $ ('Input # hidden_is_url') Val (0). }   

HTML:

// Content to be loaded in the attachment

  var content = '& lt; Div class = "extracted_url" & gt; '+ Inc_image +' & lt; Div class = "extracted_content" & gt; & Lt; H4 & gt; & Lt; A href = "'+ extracted_url +'" target = "_ blank" & gt; '+ Data.title +' & lt; / A & gt; & Lt; Img class = "close_url" src = "'+ IMAGE_PATH +' / cross-gray page" /> & lt; / H4 & gt; & Lt; P & gt; '+ Data.content +' & lt; / P & gt; & Lt; Div class = "thumb_sel" & gt; & Lt; Span class = "prev_thumb" id = "thumb_prev"> gt; & Amp; Nbsp; & Lt; / Span & gt; & Lt; Span class = "next_thumb" id = "thumb_next" & gt; & Amp; Nbsp; ; & Lt; / Span & gt; & Lt; Span class = "small_text" id = "total_imgs" & gt; '+ Img_arr_pos +' of '+ total_images +' & lt; / Span & gt; & Lt; Span class = "small_text" & gt; & Amp; Nbsp; & Amp; Nbsp; Select a thumbnail & lt; / Span & gt; & Lt; / Div & gt; & Lt; / Div & gt; ';   

/ * The above html that I am connecting with the Javascript function. And it's not inside. * *

Looks like you .click code & lt ; A & gt; is in the DOM before the tag (i.e. before the DOM ready event.

Make sure the code is wrapped on an event, such as this:

  $ Click on the document (function () {.});});    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -