skip to Main Content

Here’s the code that I have, where I need to update the "Charge Amount" to something else using JavaScript
I’ve tried various things but haven’t been successful. There’s no id associate to the ul or the li items. What’s the best way to update this?

<ul class="properties">    
<li>
      <label>
          <b> Charge Amount </b>
      </label>
    </li>
</ul>

2

Answers


  1. You should learn more about CSS selectors. A CSS selector for this might be

    ul.properties li
    

    or just

    .properties li
    

    The basics of CSS Selectors really isn’t that hard to learn, and it will help you moving forward.

    Login or Signup to reply.
  2. You can use the querySelector() method.

    let b = document.querySelector('ul.properties li:nth-child(1) b');
    b.textContent = 'Updated Amount';
    <ul class="properties">
      <li>
        <label>
              <b> Charge Amount </b>
          </label>
      </li>
      <li>
        <label>
              <b> Some other Amount </b>
          </label>
      </li>
    </ul>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search