What is the best way to assign a hyperlink to an entire div purely with JavaScript? [duplicate]

Everything I've searched for has shown about making a full div clickable, what I'm wondering is, is it possible to make a div in to a clickable link using just JavaScript and the div ID?

I have a layout of boxes and if a value in my database, I want PHP to echo some values in to JavaScript and say if this box is taken, give this div (boxID) the link that relates to it from the database. Only, there aren't going to be links on every div, as some won't exist in the database.

I suppose the alternative to this is wrapping each div in a <a> tag and an if exists statement?


In pure JS:

document.getElementById('your-div').addEventListener('click', function() {
    location.href = 'http://your-url.com'
}, false);

By jQuery

$('#your-div').on('click', function() {
    location.href = 'http://your-url.com'    
});

you can easily make it so that when you click your div you go to another page, like this (using jQuery)

$('#myId').click(function () {
    window.location = 'newurl.php';
});