Jquery - if url has _edit in the link then dont show a div else show
Just wondering if there is a way that you can read and search for specific refferences within a URL, put it in a url and then d开发者_高级运维o an if statement.
I want the code to be able to search for this refference "/_edit" and if its in the url then hide a div if it isnt then show it.
On load of the current page:
$(function() {
if (location.href.match(/\_edit/)) {
$('div#editor').show();
}
else {
$('div#editor').hide();
}
});
Via a click handler:
Just use the string match method on the href to choose whether to show or hide the div.
$('a').click(function() {
var href = $(this).attr('href');
if (href.match(/\/_edit/)) {
$('div#editor').show();
}
else {
$('div#editor').hide();
}
});
精彩评论