Affecting Elements
jQuery has many different methods for affecting elements.
.text()
Sets new text on an element
Gets the current text of an element
.addClass()
Adds a class to an element.
Note: period not added before is-active because .addClass already indicates that we're passing in a class name.
.removeClass()
Removes a class from an element
.toggleClass()
Adds a class if that class is not already on the element. Removes a class if that class is already on the element.
.hasClass()
Returns true or false based on if an element has a certain class
.val()
Gets the value of a form field
Sets a value on a form field
Clears the value of a form field
.remove()
Deletes an element entirely from the page
.appendTo()
Moves cta-card into the cms-list as the last child
Moves cta-card into the cms-list as the last child using variable
Makes a copy of cta-card and adds the copy as the last child of cms-list
Creates a new div with class of "cta-card" and adds it as the last child of "cms-list"
.prependTo()
Moves cta-card into the cms-list as the first child
.insertBefore()
Moves the cta-card to be right before the third cms-item
.insertAfter()
Moves the cta-card to be right after the third cms-item
.css()
Get or set the value of any css variable or css property like height, background-color, border-width, etc.
Gets the background color of the hero
Sets the background color of the hero
Gets the value of the --swatch--brand css variable on the html element
Sets the value of the --swatch--brand css variable on the html element
.attr()
Gets or sets the value of any attribute
Gets the href (url) on a link
Sets the href (url) on a link
Gets the source (url) of an image
Sets the source (url) of an image
When using this, select the image in Webflow and ensure the "Disable responsiveness" checkbox is turned on. Otherwise multiple image sources will be generated for each screen size.
Get the arial-label of an element
Set the arial-label of an element
Get the value of a custom data attribute
Set the value of a custom data attribute
.removeAttr()
Deletes an attribute and its value completely from an element
.click()
Causes a click on an element
If the element is a link, [0] is needed because only one link can be clicked at a time.
.clone()
Makes a copy of an element
Shortened version
.html()
Gets the html inside an element
Replaces the html inside an element
Clears out the html inside an element
.empty()
Deletes everything inside an element
.wrap()
Wrap something around an element. New div with the class of "container" gets wrapped around my-element
.unwrap()
Deletes the direct parent of an element without deleting any of that parent's children
.replaceWith()
Deletes element and replaces it with something else
Replace with existing element
The hero-card will be deleted and the footer-form will be moved to where the .hero-card was.
Replace with new element
The hero-card will be deleted, and a new h2 will be created in its place.
.prop()
Gets or sets the value / state of a form element
When using a custom checkbox style, Webflow hides the real checkbox input and adds a div styled like a checkbox in its place.
Sets checkbox to checked
Sets checkbox to unchecked
Get value of checkbox
Get state of checkbox
.height()
Get the height of an element
Set the height of an element
This can also be done with .css("height") and .css("height", "2rem")
.width()
Get the width of an element
Set the width of an element
.show()
Sets element to display block
Can also be done with .css("display", "block")
.hide()
Sets element to display none
.toggle()
Switches between display none and the original display setting
.focus()
Causes a focus on an element
.blur()
Causes a focus off of an element
.submit()
Causes a form to submit
The <form> element in Webflow is the direct child of the Form Block.
Last updated