jQuery HTML manipulation using html(), text(), val(), attr()  methods

HTML manipulation using html(), text(), val() and attr() methods

Method Chaining Examples

    • html(), text(), val() and attr().
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


            width: 300px;
            border: 1px solid black;
<div class="box">
    <p>this is paragraph</p>
    <h1>this is heading1</h1>
    <h2>this is heading2</h2>
    <h3>this is heading3</h3>

<a href="https://www.google.com" class="id">google</a>

<input type="text" class="box2">

<button class="set">html()</button>
<button class="set2">text()</button>
<button class="set3">val()</button>
<button class="set4">attr()</button>

<script src="jquery-3.6.0.min.js"></script>


alert("Text: " + $(".box").html())

alert("Text: " + $(".box").text())

alert("Text: " + $(".box2").val())

alert("website: " + $("a").attr("href"))



 Tags: html(), text(), val() and attr(), jquery, jquery code snippets