search

Home  >  Q&A  >  body text

Hide the first element of a div

<p>I have a div that displays this text</p> <pre class="brush:php;toolbar:false;"><address class="address address--tight"> -17.7353231,-63.1696634, Av. Block, NY00, Miami, United States </address></pre> <p>How can I hide the first two elements (coordinates) and only show the address, city and country? </p>
P粉278379495P粉278379495466 days ago420

reply all(1)I'll reply

  • P粉127901279

    P粉1279012792023-08-18 09:53:26

    According to the code provided, you can directly get the element's .textContent, then .split on ,, remove the first two parts, and then Use , to .join. This method is very specific though and may fail if you are not 100% sure that you always have this order and these details.

    const address = document.querySelector( 'address' );
    
    address.textContent = address.textContent.split( ',' ).slice( 2 ).join( ',' );
    <address class="address address--tight">
          -17.7353231,-63.1696634, Av. Block, NY00, Miami, United States
    </address>

    reply
    0
  • Cancelreply