'how to I change <h2> tag with Javascript or CSS [closed]

Is there a way to change the text in the h2 inside a class using css or javascript? I think it is possible through JS but not sure how.

Please note that I cannot change span or give id. Also, I have multiple sections that uses the same div class "twocol-box1 superflex-content-6-12" but only one section with the H2 text "old text".

Here is what I have

<div class="twocol-box1 superflex-content-6-12">
  <h2>old text</h2>


Solution 1:[1]

You can access the h2 inside a div whose class is "twocol-box1 superflex-content-6-12" by using javascript "querySelector" method :

const h2Tag = document.querySelector("twocol-box1 superflex-content-6-12 > h2");

Note that querySelector method acts like a CSS selector.

Then, the content of an element can be changed using the "innerHTML" property :

h2Tag.innerHTML = 'New text';

Solution 2:[2]

Try

var elem = document.querySelector("div.twocol-box1.superflex-content-6-12 h2");
elem.innerHTML = "new text"

You select the "h2" Tag in a div with the classes twocol-box1 and superflex-content-6-12 and change the Text with innerHTML method

Solution 3:[3]

Do not use the array constructor to stack your arrays but:

vecs_train_LV = np.r_[[norm_vector(sentence, model_level, sw_indo) for sentence in data.data]]

Or:

vecs_train_LV = np.vstack([norm_vector(sentence, model_level, sw_indo) for sentence in data.data])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sebastiencn
Solution 2 Voidy
Solution 3 mozway