Get selected value of a dropdown’s item using jQuery
For single select dom elements, to get the currently selected value: $(‘#dropDownId’).val(); To get the currently selected text: $(‘#dropDownId :selected’).text();
For single select dom elements, to get the currently selected value: $(‘#dropDownId’).val(); To get the currently selected text: $(‘#dropDownId :selected’).text();
There’s a .val() method: If you’ve got an input with an id of txtEmail you can use the following code to access the value of the text box: $(“#txtEmail”).val() You can also use the val(string) method to set that value: $(“#txtEmail”).val(“something”)
$(‘.class1, .class2’).on(‘click’, some_function); Or: $(‘.class1’).add(‘.class2’).on(‘click’, some_function); This also works with existing objects: const $class1 = $(‘.class1’); const $class2 = $(‘.class2’); $class1.add($class2).on(‘click’, some_function);
if ($(‘input.checkbox_check’).is(‘:checked’)) {
The callbacks attached to done() will be fired when the deferred is resolved. The callbacks attached to fail() will be fired when the deferred is rejected. Prior to jQuery 1.8, then() was just syntactic sugar: promise.then( doneCallback, failCallback ) // was equivalent to promise.done( doneCallback ).fail( failCallback ) As of 1.8, then() is an alias … Read more
The short answer taken from the announcement of jQuery 3.0 Final Release : Along with the regular version of jQuery that includes the ajax and effects modules, we’re releasing a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code. The file size (gzipped) is about 6k smaller, … Read more
What’s going on!? “jQuery probably copies those properties into the jQuery object.” You’re exactly correct, so it sounds like you already know! 🙂 Hopefully jQuery will update their code to stop touching that, but at the same time WebKit should have known better than to log a deprecation warning on an event (at least in … Read more
The correct way to do this is to use show and hide: $(‘#id’).hide(); $(‘#id’).show(); An alternate way is to use the jQuery css method: $(“#id”).css(“display”, “none”); $(“#id”).css(“display”, “block”);
Put modal(‘toggle’) instead of modal(toggle) $(function () { $(‘#modal’).modal(‘toggle’); });
It depends on whether you are submitting the form normally or via an AJAX call. You can find lots of information at jquery.com, including documentation with examples. For submitting a form normally, check out the submit() method to at that site. For AJAX, there are many different possibilities, though you probably want to use either … Read more