Answer the question
In order to leave comments, you need to log in
js. Variable inside href?
Is it possible to somehow put a variable inside href?
var urlGo=http://goo.gl;
var googleLink = window.document.querySelectorAll("a[href^='urlGo']");
Answer the question
In order to leave comments, you need to log in
var link = document.querySelectorAll('a[href]');
for ($i = 0; link.length > i; i++) {
link[i].setAttribute('href', 'http://goo.gl');
}
Pure JS - only in the script, not in the template (see Viktor's and ErgonomicCode's answers).
If a lot of such good is planned, I would look towards template engines
First you need to fix the errors in the code)))
And only then ...
var urlGo="http://goo.gl"; // строки надо в кавычки брать
// можно так
var googleLink = window.document.querySelectorAll("a[href^="+urlGo+"]");
// или вот так
var selector = [
"a[href^=",
urlGo,
"]"
].join('');
var googleLink = window.document.querySelectorAll(selector);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question