The same is for JS only. How to translate?
$(document).ready(function(){ $("#form_error_message_frontend + div > div:last-child label").addClass("last"); }) The same is for JS only. How to translate?
$(document).ready(function(){ $("#form_error_message_frontend + div > div:last-child label").addClass("last"); }) Something like this:
document.addEventListener('DOMContentLoaded', function(){ // Аналог $(document).ready(function(){ // Если должен быть найден один элемент if((e = document.querySelector("#form_error_message_frontend + div > div:last-child label")) !== null) e.classList.add('last'); // Аналог выборки и присвоения класса // Если элементов будет много Array.prototype.forEach.call(document.querySelectorAll("#form_error_message_frontend + div > div:last-child label"), function(e){ e.classList.add('last'); }); }); querySelector , but a querySelectorAll plus an iteration over the returned NodeList . - VisioNlast class unambiguously hints that there is only one element, which means that you can search through querySelector . Although if the TS is wrong, then rewrite :) - user31688label elements in the last block. In this case, purely logically, the added class "last" may refer not to the last label , but to all label in the last block. - VisioNquerySelector does not work out, for querySelector you can add a check for the presence of the returned element before accessing the classList property: well, how will undefined return? - VisioNgood answer is here
90 +% of browsers will cover this solution to wait for the download to finish.
document.addEventListener("DOMContentLoaded", function(event) { //do work }); for 95 +% of browsers, you can use the methods querySelector / querySelectorAll
var el = document.querySelector("#form_error_message_frontend + div > div:last-child label"); el.className += el.className ? ' last' : 'last' Perhaps you will only need to add deferred script loading with the "defer" attribute to <script> So the script will wait for the entire DOM tree to load, and then it will start.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Пример</title> <script language="JavaScript"> function startFunction() { alert("Hi there!"); } </script> </head> <body onload="startFunction()"> </body> </html> Source: https://ru.stackoverflow.com/questions/414516/
All Articles