I am trying to check event.target.nodeName as follows:
$("input").click(function(e){ if(e.target.nodeName == "LABEL") { alert('label click'); e.preventDefault(); } else { alert($(this).attr('checked') ? 'checked': 'unchecked'); } });
But the name never matches the label? What am I doing wrong?
Fast jsfiddle
You must select the label (parent) element. Currently, the sole purpose of your click handler is the input element:
label
$("label").click(function(e){ // ... })
http://jsfiddle.net/j7nSq/
I think the reason is that this does not work, because it will only work when clicking on the input:
if(e.target.nodeName == "LABEL") {
You do not select a shortcut at all. First select the shortcut and try again:
You get into the wrong item here.
$('label').on('click', function(e) { // Your logic here });
Instead of clicking on input.
Make sure you delegate the event using .on() .
.on()
Source: https://habr.com/ru/post/1436016/More articles:CMake: what is the purpose of matching a variable with itself? - cmakehttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1436012/rpostgresql-access-to-database-error-unable-to-find-an-inherited-method-for-function-show-for-signature-postgresqlconnection&usg=ALkJrhiVHImj-UWAB_gVZwpwMD3B_yG7dgHow to create a user with cook cookbook for universal users? - chefshow activity indicator when loading ViewController - iphoneFusion of built-in math functions does not work in imported files - alloyTwo-dimensional array, what does * (pointerArray [i] + j) do? - c ++clojure vector cache - cachingWindows 8 metro app collectionviewsource data binding problem - data-bindingMany foreign keys - Django Admin - sqlDjango admin list_display weirdly slows down with foreign keys - performanceAll Articles