jQuery Essentials by Miles Troy

jQuery Essentials by Miles Troy

Author:Miles, Troy [Miles, Troy]
Language: eng
Format: azw3, mobi
Publisher: Packt Publishing
Published: 2016-01-30T05:00:00+00:00


This code sample is nearly identical to the previous sample, except the focus and blur events have been replaced with the focusin and focusout events, respectively. We again hook the parent fieldset element. This time, however, the events bubble up to their parent. We add the active class to the fieldset and even display which element generated the event by getting its ID from the target property of the event object.

// Adds an input tag dynamically by clicking the "Add Another" button var inputCounter = 0; $('#addAnother').click(function (event) { console.info("Adding another"); $('#inputMomma').append($("<input>").attr({'type': 'text', 'id': 'newInput' + inputCounter++})); }); // Makes the parent element the active class $('#inputMomma').focusin(function (event) { console.info('Focusin: ' + this.id + ', triggered by: ' + event.target.id); $(this).addClass('active'); }); // Removes the active class from the parent $('#inputMomma').focusout(function (event) { console.info('FocusOut: ' + this.id + ', triggered by: ' + event.target.id); $(this).removeClass('active'); });



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.