I have the following html:
<a class="expander" id="menMenu" onclick="expandMenu(this,event); return false;" href="" >Men</a>
When the page has loaded I want to read the URL and, if it contains the word 'men', I want the above link to be clicked.
Here's what I'm trying, console log works but the click doesn't happen:
window.onload = function() {
var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
var myWord = 'men';
var a = new RegExp('\\b' + myWord + '\\b');
var b = (a.test(newURL));
if(b=true){
console.log('true'); // this shows 'true' in console
document.getElementById("menMenu").click();
}
};