27
loading...
This website collects cookies to deliver better user experience
<script src=”https://code.jquery.com/jquery-3.1.1.js”></script>
$("selector").action()
$("div") // => selects all div elements
$(".menu") // => selects element with class name of "menu"
$("#header") // => selects element with id of "header"
$("form.search") // => selects <form> element with class name of "search"
$("p:first") // => selects the first <p> element
$(“div p”) => selects all <p> elements that are children of a <div> element
document.querySelector()
or document.getElementById()
. If you realized this, good job! You are making connections and that is amazing. $("a").attr("href", "www.google.com")
<a href="www.google.com"></a>
let x = `
<input id="input"
placeholder="search your saved items">
`
// add a class attribute
$("input").attr("class", "search")
// remove the id attribute
$("input").removeAttr("id")
<input class="search" placeholder="search your saved items">
The .html() method is used to retrieve OR change the content of the selected element, including the HTML markup.
The .text() method is used to retrieve OR change the text content of the selected element.
The .css() method can be used to get and set CSS properties.
The .val() method allows us to get AND set the values of form fields, such as textboxes, dropdowns and inputs.
The .append() method inserts content at the end of the selected element(s).
The .prepend() method inserts content at the beginning of the selected element(s).
The .after() method inserts content with HTML markup after the selected element(s).
The .before() method inserts content before with HTML markup the selected element(s).
The .addClass() method adds a class to the element called on.
The .removeClass() method removes the class of the element called on.
The .toggleClass() method toggles between adding and removing classes from selected elements. If the specified class exists already, it is then removed. If the specified class does not exist, it is added.
The .width() and .height() methods can be used to get and set the width and height of HTML elements.