Run JavaScript code via web browser console. | Drupal 8

Run JavaScript code via web browser console.

Submitted by editor on Tue, 06/06/2017 - 14:48
Question

On Firefox and Chrome how to run JS codes using browser console ?

Note : Following examples are tested on FireFox Version 52.

Open Web browser console. F12

Method 1 . Press F12 and click on "Console"
Method 2 . Press Ctrl + Shift + K

Example 1. Test the console.

Type alert('Hello'); this will open a "Hello" dialog box.

Example 2. Change input value by ID. ()

document.getElementById("the_element_id").value

Example 3. Change all inputs (checkbox) start with 'variable' to 'checked'

Note : I use this example to activate features on Drupal 7

var eles = [];
var inputs = document.getElementsByTagName("input");
for(var i = 0; i < inputs.length; i++) {
    if(inputs[i].name.indexOf('variable') == 0) {
        inputs[i].checked = 'checked';
    }
}

Add new comment