-3

I'm having problems trying to figure this out, specifically because I'm really new to javascript. So, I have this place in my page where I want to have a random html file that I will make in html and I will like to link to it. I want it to be randomized every time the page refreshes, because I will do lots of these html files.

So, is this possible? I've searched for answers but all of the randomized html questions I've found are about the whole page. I just want a little part of the page to be randomized, similar to the random image I have in the same webpage.

The page I'm using for testing is this one: http://vannapruebas.jcink.net/ , I would like to use the toggle that says "búsquedas" for this. So, any help? thanks and exuse my poor english!

1 Answers1

0

All you have to do is make a list of all your html, then you pick one randomly with -> Getting a random value from a JavaScript array.
I used jQuery just for easier demo

var listOfHTML = ["sample/your.html","sample/another.html"];

$('#magic').on('click',function(e){
    var randomHTML = listOfHTML[Math.floor(Math.random()*listOfHTML.length)];
    $.get(randomHTML,function(response){
        $('#yourDiv').html(response);
        //do your animation when completed  
    });
});
<div id="yourDiv"></div> <button id="magic">búsquedas</button>
Community
  • 1
  • 1
  • It works! Sadly, I kinda confussed myself and the code I want to be randomized is an html file, since I can work without the css being randomized. In that case, do I have to do the same thing? Because I tried and it didn't work. Sorry for the mistake :'D – Ivanna Von Rodt Jun 19 '16 at 03:00