0

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?

Martin.
  • 10,271
  • 3
  • 40
  • 67
user989865
  • 617
  • 3
  • 8
  • 21

5 Answers5

2

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.

Sarfraz
  • 367,681
  • 72
  • 526
  • 573
0

Use can have the current url with :

$(location).attr('href');

After that, you can use jQuery to remove your div :

$("#myDivId").remove();
Mathieu Mahé
  • 2,575
  • 2
  • 33
  • 47
0
if (/dispform.aspx$/.test(document.location.toString())) {
 // code to remove element
}
Kae Verens
  • 3,983
  • 3
  • 20
  • 40
0

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?

Community
  • 1
  • 1
Thein Hla Maw
  • 687
  • 1
  • 9
  • 28
0

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.

jfriend00
  • 637,040
  • 88
  • 896
  • 906