js get element by selector code example

Example 1: how to get element by title js

var node = document.querySelector('[title="element title attribute value"]');

Example 2: queryselector

var el = document.querySelector(".myclass");

Example 3: javascript get element by id

var myElement=document.getElementById("someElementID");

Example 4: javascript queryselector

//Pretend there is a <p> with class "example"
const myParagraph = document.querySelector('.example');
//You can do many this with is
myParagraph.textContent = 'This is my new text';

Example 5: queryselector for jquery

var x = $(".yourclass")[0];
console.log('jq' + x);
var y = document.querySelector(".yourclass");
console.log('js' + y);

Example 6: js queryselector

const para = document.querySelectorAll('p');