jquery $(".classname").Which Javascript grammar has the same meaning as html("test_text")?

Asked 2 years ago, Updated 2 years ago, 40 views

$(".classname").html("test_text");

In this way, we stacked text in html in the class using jquery.

I want to avoid using Jquery grammar as much as possible, but javascript can stack strings in the class with the same meaning What grammar is there?

document.getElementById("test_id").innerHTML = "<p>123</p>"

I stacked it on ID like this

document.getElementByClassName("test_class").innerHTML = "<p>123</p>"

Why doesn't it move?

jquery javascript html css

2022-09-22 13:23

1 Answers

getElementsByClassName() returns HTMLCollection.This is kind of a list. So you have to go around the list to do what you want.

var elems = document.getElementsByClassName('classname');
for (i = 0, len = elems.length; i < len; i++) {
    elems[i].innerHTML = '<p>123</p>';
}


2022-09-22 13:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.