How do I access a particular part of an HTML tag?

18
May 19, 2019, at 1:30 PM

I am using console on google chrome to edit the web page. I could just use inspect element and change what I am trying to change, but after discovering I could do this on the console... I wanted to do it that way.

Here is the code of the website as it is now:

  • Name:Mountain, Rocky 
  • I am trying to replace Mountain, Rocky so it says "Mountain, Appalachia"

    So far, I've tried: document.getElementByTagName("li")[12].replaceWith("Name:Mountain, Rocky ");

    and lots of other combinations (replacing the quotes inside the replaceWith with &quot, just writing "Name: Mountain, Appalachia&nbsp" and nothing works

    most of the time the change I want to make shows up in the "Name:" part and the Mountain, Rocky goes away.

    How do I maintain the Name: and the Mountain part of the code?

    Answer 1

    I assume that document.getElementByTagName("li")[12] is your <li> element. To change inner text of element you can use:

    • innerText - document.getElementByTagName("li")[12].innerText = 'Mountain, Appalachia'
    • innerHTML - document.getElementByTagName("li")[12].innerHTML = 'Mountain, Appalachia'

    Similiar questions were answered many times. For example here

    READ ALSO
    How to use an array to query

    How to use an array to query

    Is there any way I can use the array from $query and use it in another query like the $query2 below? It works but it only returns the first data of the array

    39
    MySQL query with COUNT and ORDER BY and hidden results

    MySQL query with COUNT and ORDER BY and hidden results

    Im trying to get a query correct where I can display the data by State with each of the States cities with stores in it with the COUNT (Number of stores in each city)Any help is greatly appreciated

    36
    Only allow users on page if IP address is approved

    Only allow users on page if IP address is approved

    How can I make an HTML (and CSS/PHP/JavaScript) document which only allows certain IP addresses on a page?

    55
    What is the proper Query and PHP to print an archive of the database based on Year, Month?

    What is the proper Query and PHP to print an archive of the database based on Year, Month?

    I've found plenty of examples that either don't show the query, or don't show the codeI'm looking to format the output as such:

    30