I want to randomly change my a tag link with refreshing browser using javascript pls tell me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I want to randomly change my a tag link with refreshing browser using javascript pls tell me

Using an array , random function

20th May 2021, 7:03 AM
Webber
Webber - avatar
7 Answers
+ 3
Assuming you know how to make that URL array, next thing to learn is to choose random element from the array. https://www.w3schools.com/JS/js_random.asp Make sure the hyperlink can be uniquely identified, by setting its "id" attribute for example. Next you obtain the hyperlink reference (by its "id") and set its 'src' attribute via Javascript. <hyperlink-element>.src = <random-url-from-array>; Still not getting the browser refresh thing though ...
20th May 2021, 7:25 AM
Ipang
+ 3
So you have a hyperlink in a page, And now you want the 'src' attribute to contain random URL taken from an array, is that what you want? But what about the browser refresh? I didn't get it.
20th May 2021, 7:16 AM
Ipang
+ 2
Webber, I can't respond to DM, it is read-only for me. My replies never got through back to the sender.
20th May 2021, 7:18 AM
Ipang
+ 2
Webber bro, Then please join Javascript course to learn about arrays. I thought you knew about it because you mentioned "using array, random function" in the Description above.
20th May 2021, 8:30 AM
Ipang
+ 1
Ok
20th May 2021, 7:18 AM
Webber
Webber - avatar
+ 1
Please tell me how can I do it
20th May 2021, 7:19 AM
Webber
Webber - avatar
0
No bro I don't know to make.a url array pls help me
20th May 2021, 8:19 AM
Webber
Webber - avatar