How do i check if the current URL contains the sub-string using jQuery or javascript?
I need to select a anchor tag using class if a condition is met, suppose i need to check if URL has "/CRM" then select
if(URL.hasString('/CRM'))
{
$(".SelectURL").RemoveClass('Hide');
}
How to do it using jQuery or javascript?
You can check if a string contains substring in javascript by taking the URL using windows.location.href and then check the sub-string using .IndexOf("Substring") method , so your complete code will be as below
if (window.location.href.indexOf("/CRM") > -1) {
alert("Inside /CRM");
}
Or Second Method you can do it like below
if (location.href.match(/CRM/)) {
alert("in CRM ");
}
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly