IF in JQuery

Hello Experts!

I have a function:

$(document).ready(function()
        {
         $("form[name*='Form1']").each(function(){
                  $("a.NALink", this).click(function(){
                  var confirmNA = confirm("You are about to delete last year's answer(s). Are you sure you want to delete this information?");
                  return confirmNA
                  });  
               });      
         });

It DOES NOT work as it's supposed to.

It SHOULD check if there's element ("form[name*='Form1']") EXISTS on the Page.

If it does, AND user clicks the link $("a.NALink", this).click ONLY THEN

the Confirm-Cancel Pop-up should appear.

NOW it works always and not checking if element  ("form[name*='Form1']") EXISTS.

Should I add "If" statement to the function and if yes, what will be the syntax for that?

Thanks!
snarinskyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Albert Van HalenAnalyst developerCommented:
Weird.
Your getting the link within the context of the form...

What happens if you use  $("form[name*='Form1']").find("a.NALink")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vasanthgovindCommented:
use if($("form[name*='Form1']").length > 1)  to check if the form exists or not



 
$(document).ready(function()
        {
           if($("form[name*='Form1']").length > 1) {
                  $(this+" > a.NALink", this).click(function(){
                  var confirmNA = confirm("You are about to delete last year's answer(s). Are you sure you want to delete this information?");
                  return confirmNA
                  });               
           }      
         });   

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.