Category: 3. JQuery Minipulation

  • jQuery innerWidth() and innerHeight() Methods

    The jQuery innerWidth() and innerHeight() methods get or set the inner width and the inner height of the element respectively. This inner width and height includes the padding but excludes border and margin on the element. The following example will return the inner width and height of a <div> element on the click of a button. Example Similarly, you can set the element’s inner width and height by passing the value…

  • jQuery Dimensions

    Understanding the jQuery Dimensions jQuery provides several methods, such as height(), innerHeight(), outerHeight(), width(), innerWidth() and outerWidth() to get and set the CSS dimensions for the elements. Check out the following illustration to understand how these methods are calculating the dimensions of an element’s box. jQuery width() and height() Methods The jQuery width() and height() methods get or set the width and the height of the element respectively. This width and height doesn’t include padding, border and margin on the…

  • Set Multiple CSS Properties and Values

    You can also set multiple CSS properties with the css() method. The basic syntax for setting the more than one property for the elements can be given with: $(selector).css({“propertyName”:”value”, “propertyName”:”value”, …}); The following example will set the background-color as well as the padding CSS property for the selected elements at the same time. Example

  • jQuery Get and Set CSS Properties

    jQuery css() Method The jQuery css() method is used to get the computed value of a CSS property or set one or more CSS properties for the selected elements. This method provides a quick way to apply the styles directly to the HTML elements (i.e. inline styles) that haven’t been or can’t easily be defined in a stylesheet. Get a CSS Property…

  • jQuery removeClass() Method

    Similarly, you can remove the classes from the elements using the jQuery removeClass() method. The removeClass() method can remove a single class, multiple classes, or all classes at once from the selected elements. The following example will remove the class .page-header from the <h1> and the class .hint and .highlight from the <p> elements on button click. Example When the removeClass() method is called without an argument it will remove all…

  • jQuery Add and Remove CSS Classes

    jQuery CSS Classes Manipulation jQuery provides several methods, such as addClass(), removeClass(), toggleClass(), etc. to manipulate the CSS classes assigned to HTML elements. jQuery addClass() Method The jQuery addClass() method adds one or more classes to the selected elements. The following example will add the class .page-header to the <h1> and the class .highlight to the <p> elements with class .hint on button click. Example You can also add multiple classes to…

  • jQuery unwrap() Method

    The jQuery unwrap() method removes the parent elements of the selected elements from the DOM. This is typically the inverse of the wrap() method. The following example will remove the parent element of <p> elements on button click. Example jQuery removeAttr() Method The jQuery removeAttr() method removes an attribute from the selected elements. The example below will remove the href attribute form the <a> elements on button click. Example

  • jQuery Remove Elements & Attribute

    jQuery Remove Elements or Contents jQuery provides handful of methods, such as empty(), remove(), unwrap() etc. to remove existing HTML elements or contents from the document. jQuery empty() Method The jQuery empty() method removes all child elements as well as other descendant elements and the text content within the selected elements from the DOM. The following example will remove all the content inside…

  • jQuery before() Method

    The jQuery before() method is used to insert content before the selected elements. The following example will insert a paragraph before the container element on document ready, whereas insert an image before the <h1> element on button click. Example Note: The contents or elements inserted using the jQuery before() and after() methods is added outside of the selected elements. jQuery after() Method The jQuery after() method is used…

  • jQuery Insert Content

    jQuery Insert New Content jQuery provides several methods, like append(), prepend(), html(), text(), before(), after(), wrap() etc. that allows us to insert new content inside an existing element. The jQuery html() and text() methods have already covered in the previous chapter, so in this chapter, we will discuss about the rest of them. jQuery append() Method The jQuery append() method is used to insert content to the end of the selected…