I have a simple form with some text input elements.
Somewhere outside of this form, I have a span element which triggers a formSubmit()
function when clicked (doing some ajax stuff).
HTML:
<span id="submit">
<img src="saveIcon.png" />
</span>
JQuery:
$('#submit').click( formSubmit );
This worked perfectly.
Then I wanted the icon to change: initially set to "saveIconGrey.png", it shall be replaced by "saveIconActive.png" as soon as the user changes anything in any input field.
I coded a simple setSaveIcon()
function to do that.
This function is called on change events like this:
$('input').change( setSaveIcon );
This also works perfectly...
But now, when the user modifies an input value and clicks on the submit span, only the "change" event is triggered.
User has to click on the submit span a second time to trigger the click event (and then the ajax stuff is triggered and works perfectly).
It looks as though the $('input').change()
event would be hiding the $('#submit').click()
event, where both should be fired when the user clicks out of the modified input and in the submit span by the same click.
I found nothing, neither in the jquery documentation nor here. I tried some "return true", "return false" in setSaveIcon()
in case it were some kind of propagation problem, it didn't change anything.
I must be missing something very simple...
Edit:
Sample code here: https://jsfiddle.net/brd59fpz/2/
Edit 2:
Previous code is irrelevant, sorry.
Problematic code sample here: https://jsfiddle.net/d88u0snf/
And corrected code here: https://jsfiddle.net/d88u0snf/1/
(I posted an answer for further details)