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?

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Use can have the current url with :

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

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

$("#myDivId").remove();

Comments

0
if (/dispform.aspx$/.test(document.location.toString())) {
 // code to remove element
}

Comments

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?

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.