Search code examples
javascriptbookmarklet

Edit html certain element from chrome bookmark


I am running javascript by clicking a chrome bookmark to edit certain html element. When I run javascript:void(console.log(document.getElementById("main_frame"))), I got the result as shown in picture below. However, I could not get the element under the #document for example the 'container' in . How can I get the element under #document?

enter image description here


Solution

  • try like this:

    var _iframe = document.getElementById('iframeId').contentWindow;
    var _div =_iframe.document.getElementById('objId');
    _div.style.backgroundColor = '#ccc';