So basically, I have something like this:
<h2 class="clickable">Hello</h2>
And I want to make it clickable. I know it’s kind of a strange question because I can just insert an a tag in there but this is how I need to do it right now. How would I do this? Is it anything like the code below? I’m kind of lost.
$(".clickable").click(function(){
window.location=$(this).attr("href");
return false;
});
You need to have a target URL (what you are referring to with
href). The correct way for that in HTML5 would be a data attribute.This is the HTML5:
This is the JS:
If you want the new link to open in a new window, use this code: