This jQuery cheat sheet is a great reference for both beginners and experienced developers.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
$(selector).methodOrFunction();
$('#menu').on('click', () =>{
$(this).hide();
});
$("body").css("background", "red");
$(document).ready(function() {
// Runs after the DOM is loaded.
alert('DOM fully loaded!');
});
$(function(){
// Runs after the DOM is loaded.
alert('DOM fully loaded!');
});
$('h2').css({
color: 'blue',
backgroundColor: 'gray',
fontSize: '24px'
});
$('.button').addClass('active');
$('.button').on('mouseleave', evt => {
let e = evt.currentTarget;
$(e).removeClass('active');
});
$('.choice').toggleClass('highlighted');
/*<span>Span.</span>*/
$('span').after('<p>Paragraph.</p>');
/*<span>Span.</span><p>Paragraph.</p>*/
/*<span>Span.</span>*/
$('<span>Span.</span>').replaceAll('p');
/*<p>Span.</p>*/
/*<span>This is span.</span>*/
$('span').wrap('<p></p>');
/*<p><span>This is span.</span></p>*/
// A mouse event 'click'
$('#menu-button').on('click', () => {
$('#menu').show();
});
// A keyboard event 'keyup'
$('#textbox').on('keyup', () => {
$('#menu').show();
});
// A scroll event 'scroll'
$('#menu-button').on('scroll', () => {
$('#menu').show();
});
$('#menu').on('click', event => {
$(event.currentTarget).hide();
});
$('#menu-btn').on('mouseenter', () => {
$('#menu').show();
}).on('mouseleave', () => {
$('#menu').hide();
});
$( "p" ).click(function( event ) {
event.stopPropagation();
// Do something
});
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize()
}).done(function(server_data){
console.log("success" + server_data);
}).fail(function(jqXHR, status, err){
console.log("fail" + err);
});