Midwest Dev Chat


  • The newest 15 messages in the super-cool #javascript channel.

  • 05/20 21:48:04 Leana: Hey guys, I'm having an issue with selecting elements on this page in jQuery: https://www.wunderground.com/weather/us/ne/kear... So I'm trying to get the text New York, NY. Using the `$("div h1"`) with the console returns:
      <h1 _ngcontent-c2="">New York, NY
        <i _ngcontent-c2="" class="fi-star favorite-star"></i>
        <i _ngcontent-c2="" class="fi-home homecity-button"></i>
    However, using `$("div h1").text();` gets me an `Uncaught TypeError: Cannot read property 'text' of undefined` Any advice for this JS noob?
  • 05/20 21:53:38 Lane: DevTools doesn’t actually give you jQuery, just jQuery-like selectors, I think?
  • 05/20 21:55:07 Lane: https://developers.google.com/web/tools/chrome-...
  • 05/20 21:55:25 Dorotha: It’s about as easy without jQuery slightly_smiling_face
    let headers = Array.from(document.querySelectorAll('div h1'))
    let text = headers.map(header => header.innerText);
    console.log(text); // this will be an array of h1 text
    This presumes you could have more than one div > h1, but obviously tweak as needed
  • 05/20 22:17:37 Leana: Huh, I need to rebrush up on my JavaScript. Thanks
  • 05/20 22:18:31 Leana: @Lane Oh, I didn't know that. I just assumed that if typing '$' works, the page has jQuery
  • *Usernames have been changed to protect the innocent.
We're currently 1059 members strong. Join us!
Request Invite

Check out all the cool channels!

Join the conversation!