J
J
Juiseed2021-07-01 01:29:27
JavaScript
Juiseed, 2021-07-01 01:29:27

How to add an attribute to a tag using JS?

There is a yukoz system file that is loaded automatically with the page:

<link href="/.s/src/uAdmDesktop/css/uadm.css" rel="stylesheet" type="text/css" />

https://mmo-obzor.ru/.s/src/uAdmDesktop/css/uadm.css

Another file is loaded from it https://mmo-obzor.ru/.s/src/uAdmDesktop/css/uadm-f ... , which google pagespeed complains about for missing the rel=preload attribute. How to add this attribute to the tag using js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Brendan Castaneda, 2021-07-01
@ae_ph

Something like this can be added.
You need to select or lookup an element by its id let liElem = document.getElementById("id");
Or by tag name let liElem = document.getElementsByTagName('link');
Depending on this, delete unnecessary.
You can add an id to the desired element and call a function on it after the page is loaded.

function addAtrib() {
    let yourElem = document.getElementById("id");
    let yourElem = document.getElementsByTagName('link');
    yourElem.setAttribute('rel', 'preload');
};

window.addEventListener("load", addAtrib);

Fedor Vlasenko speaks his mind. I didn’t immediately catch up with something that it’s not on your server.
Then you won't even need a script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question