HOW TO grab text from a HTML list or dropdown with JavaScript & Dev Tools

Developer Tools in Chrome & Edge offers convenient ways to probe the content of web pages. Dev Tools can be invoked for specific pages open within the browser by using the F12 or Ctrl+Shift+I or the browser menu.

To extract just the text of a HTML list or dropdown identified by id property value of "country" with JavaScript & Dev Tools, use the following from the Console tab -

document.querySelector('#country').innerText

textContent returns the text content of all elements, while innerText returns the content of all elements, except for <script> and <style> elements. 

Snippets are a feature of the Sources pane in the Developer Tools. It allows you to write small scripts to execute in the context of the current page using a built-in editor. Common tasks can be scripted and kept in a collection for re-use later.

Comments

Popular posts from this blog

Maven Crash Course - Learn Power Query, Power Pivot & DAX in 15 Minutes

"Data Prep & Exploratory Data Analysis" course by Maven Analytics

Oracle Cloud Infrastructure 2024 Generative AI Professional Course & Certification Exam (1Z0-1127-24)