8 Nov 2020

Write code for h1 selector to display text as `welcome to jquery`?


To select an Element in jQuery We have to call $("h1"). By doing this, jQuery $ function selector select all available elements with H1 tag of whole XML or XHTML document.

To display text on selected element, make a call of text() function like this.
$("h1").text("Welcome To jQuery");


jQuery Syntax

$(selector).action();

jQuery tells a tell : Firstly select elements then apply Action to them.

Less Important


Same stuff can be done with JavaScript Easy. Whatever you want to print by text.

document.getElementById("Element unique id").innerHTMl = "Welcome To JavaScript";

document.getElementsByTagName("H2")[0].innerHTMl = "Welcome To JavaScript";

This call to document, select all elements it will look like an Array, but actually it's not.

Above example I have applied action to first H2 element.

document.getElementsByClassName("class_name")[0].innerHTMl = "Welcome To JavaScript";
Selects all element with specific class name, it also looks like a Array, but no.

In JavaScript Whenever you call method like document.getElementsByTagName() or document.getElementsByClassName(). It return an object of Type HTMLCollecton.

[Object HTMLCollecton]

If you check, console.log(HTMLCollecton instanceof Array) // => false

Reaction:

No comments:

No Comments

COMMENT FROM MESSAGE