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,494
  • 3
  • 42
  • 68
user989865
  • 627
  • 3
  • 9
  • 25

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
  • 377,238
  • 77
  • 533
  • 578
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,647
  • 3
  • 35
  • 50
0
if (/dispform.aspx$/.test(document.location.toString())) {
 // code to remove element
}
Kae Verens
  • 4,076
  • 3
  • 21
  • 41
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
  • 685
  • 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
  • 683,504
  • 96
  • 985
  • 979