Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Run JavaScript code via web browser console.

By editor , 6 June, 2017
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';
    }
}

Tags

  • Drupal 8
  • Code
  • JavaScript
  • Features
JavaScript useful tips and examples

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer