Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery mobile click event not working - DOM Prob?
    primarykey
    data
    text
    <p>tried a few combos of this the latest set of code is attached. In short I run my javascript from a separate file to the html and all I am trying to do is set up some code to watch when a checkbox is changed to run some logic on it.</p> <p>Tried watching by .document.userdetails.signal, #signal ( added the class for that ) and just plain signal.</p> <p>I would appreciate some guidance as I've looked at lots of examples many within the same html file so that why I think its the way I am trying to address the button.</p> <pre><code>&lt;form id="userdetails" name="userdetails" action="javascript: savesettings()" &gt; &lt;p&gt; &lt;p&gt; &lt;div data-role="fieldcontain"&gt; &lt;fieldset data-role="controlgroup" data-type="horizontal"&gt; &lt;input name="signal" type="checkbox" class="custom" id="signal" value="1" checked="true" /&gt; &lt;label class="signal" for="signal"&gt;Traffic Data&lt;/label&gt; &lt;/legend&gt; &lt;/div&gt; </code></pre> <p>And the Javascript</p> <pre><code> $(".document.userdetails.signal").click(function(e){ e.preventDefault(); alert('signal clicked!'); }); </code></pre> <p>Thanks</p> <p>Terran</p> <p>EDIT - Was using this example last - <a href="https://stackoverflow.com/questions/6421047/click-event-not-firing-in-jquery-mobile">Click event not firing in jQuery Mobile?</a></p> <p>EDIT2 - <a href="http://forum.jquery.com/topic/calling-a-script-when-button-clicked" rel="nofollow noreferrer">http://forum.jquery.com/topic/calling-a-script-when-button-clicked</a> Added $(document).ready so now $(document).ready(".document.userdetails.signal").click(function(e){........ seems to notice change when I open app - I guess I need to find the right target now as Jquery recreates checkboxes etc.</p> <p>EDIT 3 - Jasons solution although comments from other contributors around the target are useful. </p> <pre><code>$(function() { $("#userdetails").on("change","#signal",function(eventObj) { //do code here. eventObj.preventDefault(); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload