Skip to content
TheChatArchiveThe Chat Archive
ClaudeClaude (model unspecified)· AnthropicHugging Face ShareLM (browser-extension contributions)

In a chrome plugin (js code), how to select this div? <div contenteditable="true"…

  1. User

    In a chrome plugin (js code), how to select this div?

  2. Claude Assistant

    In a Chrome extension's JavaScript code, you can select that div using several methods:Most Specific (Recommended) javascript// By ID - most reliable since IDs should be unique const div = document.getElementById('prompt-textarea');Alternative Methodsjavascript// By class name const div = document.querySelector('.ProseMirror');

    // By multiple attributes for extra specificity const div = document.querySelector('div[contenteditable="true"][id="prompt-textarea"]');

    // By class and ID combined const div = document.querySelector('div.ProseMirror#prompt-textarea');

    // Using querySelectorAll if you expect multiple elements const divs = document.querySelectorAll('.ProseMirror');For Content Scripts If you're working in a content script, make sure you're running the code after the DOM is loaded:javascript// Wait for DOM to be ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', selectDiv); } else { selectDiv(); }

    function selectDiv() { const div = document.getElementById('prompt-textarea'); if (div) { // Do something with the div console.log('Found div:', div); } }With Error Handling javascriptfunction getPromptTextarea() { const div = document.getElementById('prompt-textarea'); if (!div) { console

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.