Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript get attribute

//HTML
//<div id="elem" data-id="4hJ3s"></div>

var elem = document.getElementById("elem");
elem.getAttribute("data-id"); // "4hJ3s"
Comment

dom element get attribute

document.getElementById('id1').getAttribute('attribute');
Comment

get html attribute value in js

<div id="id_of_the_element" data-attribute_name="foo"></div>

var elem = document.getElementById("id_of_the_element");
var attribute_value = elem.getAttribute("data-attribute_name");

//OR with jquery...
var attribute_value = $('#id_of_the_element').attr('data-attribute_name');
//OR...
var attribute_value = $('#id_of_the_element').data('attribute_name');

2nd example

//HTML
//<div id="elem" data-id="4hJ3s"></div>

var elem = document.getElementById("elem");
elem.getAttribute("data-id"); // "4hJ3s"
Comment

javascript get attribute

<div id="id_of_the_element" data-attribute_name="foo"></div>

var elem = document.getElementById("id_of_the_element");
var attribute_value = elem.getAttribute("data-attribute_name");

//OR with jquery...
var attribute_value = $('#id_of_the_element').attr('data-attribute_name');
//OR...
var attribute_value = $('#id_of_the_element').data('attribute_name');
Comment

get attribute js

element.getAttribute('id')
Comment

get attribute

const assert = require('assert')

describe('v5.webdriver.io', () => {

   
    it('should demonstrate the getAttribute command', async () => {

        browser.url('https://v5.webdriver.io')

        const input = await $('#search_input_react')

        let attr = await input.getAttribute('title')
        console.log("Title attribute is: " + attr) // outputs: "search"

        await input.setValue('test124');
        
        attr = await input.getAttribute('value')
        console.log("Value attribute is:" +  attr) // outputs: test124

        
    })
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: resize canvas 
Javascript :: combine csv files javascript 
Javascript :: data types in js 
Javascript :: window parent frames js 
Javascript :: javascript cheat sheet 
Javascript :: usereduce 
Javascript :: js value to boolean 
Javascript :: how to sort an array in js 
Javascript :: object javascript 
Javascript :: event in javascript 
Javascript :: nested callbacks javascript 
Javascript :: loopback 
Javascript :: javascript loop aray 
Javascript :: chart js 
Javascript :: clickable 
Javascript :: javascript map method 
Javascript :: JavaScript try...catch...finally Statement 
Javascript :: longest word in a string 
Javascript :: factory function vs constructor javascript 
Javascript :: array of 
Javascript :: useReducer() hook react 
Javascript :: set tiemzone datetime object 
Javascript :: .then(async 
Javascript :: How to make a toggle button in Angularjs 
Javascript :: how to set option value in fstdropdown using ajax 
Javascript :: mutation observer 
Javascript :: javascript filter array 
Javascript :: getattribute 
Javascript :: nodejs input 
Javascript :: npm whatsapp api 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =