I need to use Jquery to modify divs on some certain pages that ends with a set of filenames. So for example, if a page ends with filename dispform.aspx, I want jquery to remove a particular div when the page is loaded.
How is this achievable?
I need to use Jquery to modify divs on some certain pages that ends with a set of filenames. So for example, if a page ends with filename dispform.aspx, I want jquery to remove a particular div when the page is loaded.
How is this achievable?
So for example, if a page ends with filename dispform.aspx, I want jquery to remove a particular div when the page is loaded.
Look for file name from window.location.href
and do something like:
if (window.location.href.indexOf('dispform') > 0) {
$('#divID').remove();
}
You need to put that code in $.ready
handler.
Use can have the current url with :
$(location).attr('href');
After that, you can use jQuery to remove your div :
$("#myDivId").remove();
if (/dispform.aspx$/.test(document.location.toString())) {
// code to remove element
}
It is possible. You can get the current file name from Javascript, jQuery. Please check this post How to pull the file name from a url using javascript/jquery?
If you want to make sure this works even if there are query parameters or a hash tag, then you can do it like this:
$(document).ready(function() {
if (window.location.pathname.match(/\/dispform.aspx$/) {
$("#targetDiv").hide();
}
});
Obviously, you would put your own id in place of #targetDiv.