3

I am trying to run some JQuery script on a particular page but only if a certain page loads.

The Scenario: We have one page that loads (i.e., webpage.aspx) and it loads different content based on the referring click. (i.e., webpage.aspx?contentId=1, webpage.aspx?contentId=2, webpage.aspx?contentId=3, etc). Here is my problem. I need to have a particular part of the page removed if only one specific contentId is pulled. I am trying to do this in JQuery and can't seem to figure it out.

Here's what i have been working with so far. I realize it's not correct but hopefully it gives you a starting point to work with.

Thanks.

CODE:

$(window).load(function() {
   var $deleteNewRow = $("div.col.w140 tbody:first").find("td:first").parent().remove();
   if($('#dealer-info h1').indexOf('Ferrari') != -1) {
      $deleteNewRow
   }
});
1
  • Basically, i'm looking on the content pulled to see if it is the Ferrari content. If it IS i am deleting something from the page. But i only want to delete it for the Ferrari content. Commented Jul 23, 2010 at 20:06

2 Answers 2

1

What you store in your $deleteNewRow variable isn't the jQuery method, that method will already execute. You want to do that method in your if statement, something like this (note that you are also missing the .text() in the if statement):

$(window).load(function() {
   if($('#dealer-info h1').text().indexOf('Ferrari') != -1) {
      $("div.col.w140 tbody:first").find("td:first").parent().remove();
   }
});
Sign up to request clarification or add additional context in comments.

Comments

0

You can use jQuery :contains selector to check for the existence. Here is the docs. Then to delete find the element and then use remove.

$("div.col.w140 tbody:first").find("td:first").parent().remove();

2 Comments

can you help me by writing out the first part of the code (the part that has the "contains" in it)?
if($("#dealer-info").find("h1:contains('Ferrari')")){ $(".col.w140 tbody:first").find("td:first").parent().remove(); }else{ } The $("#dealer-info").find("h1:contains('Ferrari')") IS selecting the h1 only if it has Ferrari in it...however, the IF statement is not running properly.

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.