Answer the question
In order to leave comments, you need to log in
How to get value from html data-value attribute using jquery? How to do this without using jquery, using native browser javascript?
A bit of pre-/post-history:
Trying to do internationalization with data-values:
<p data-lang-ru="Сервис позволяет ...." data-lang-eng="The service allows ...."></p>
$('p').click(function(e){
var eng = $(this).attr('data-lang-eng');
var ru = $(this).attr('data-lang-ru');
console.log(eng);
var lang = 'eng'; // для того чтобы по клику по элементу языке менялся ru <-> eng
$(this).html(eng); // не работает toogle как задумалось, вставляется eng вместо того что надо
});
Answer the question
In order to leave comments, you need to log in
<span data-test="1"></span>
// jquery
$('span').data('test');
$('span').attr('data-test');
// vanilla js
var elem = document.querySelector('span');
elem.dataset.test;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question