I am wondering if it is possible to execute a function using just the beginning of a href, for example:
I have the following href...
<a class="title" href="example-1.html"></a>
...and wish to do the following:
var href = document.querySelector('.title').getAttribute('href');
window.onload function(){
if (href === "example/./.html"){
/* do something */
}
}
OR
var href = document.querySelector('.title').getAttribute('href');
window.onload function(){
of (href.beginsWith === "example"){
/* do something */
}
}
I don't know if they are near something possible but hopefully they give an idea of what I'd like to do. Please only Vanilla JavaScript thank you.
Thanks in advance!