if in return statement

Hello Experts,

In the code below i am trying to include an if statement so if it returns any of the given strings (e.g. 07, 17)  then hide "seb" and show "tos" BUT if not then do something else....

The problem is i am always getting an error while trying to include the "IF" right after the "return" I am guessing it is the wrong place or i should learn JavaScript better :-)

Any help ..... :-)


$("table tr td").each(function() {
  		$(this).filter(function() {			
			var thisText = $(this).text();
	  		return thisText == "07" || thisText == "17"
		}).parent().hover(function() {
	  		$(".hause-seb").hide();
			$(".house-tos").show();
		});
	});

Open in new window

RefaelAsked:
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.

Duy PhamFreelance IT ConsultantCommented:
Since you seem only need to check the text of table cells, so try to use plain if statement without filter function. For example:
        $("table tr td").each(function() {
                var thisText = $(this).text();
                if (thisText == "07" || thisText == "17") {
		        $(this).parent().hover(function() {
	  		    $(".hause-seb").hide();
			    $(".house-tos").show();
		        });
                }
                else {
                        // do something else when text is not 07 or 17 here
                }
	});

Open in new window

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
RefaelAuthor Commented:
Hi Duy Pham

For some reason the script is not working when else should execute.
0
RefaelAuthor Commented:
Thank you Duy Pham.

I just needed to include the function again inside the else for it to work :-)
Thank you!
0
Duy PhamFreelance IT ConsultantCommented:
What was the issue with else? Have you managed to get it to work?
0
RefaelAuthor Commented:
Hello Duy Pham,

I only needed to include the function once more right after the "else"... :-) Thank you!

$("table tr td").each(function() {
                var thisText = $(this).text();
                if (thisText == "07" || thisText == "17") {
		        $(this).parent().hover(function() {
	  		    $(".hause-seb").hide();
			    $(".house-tos").show();
		        });
                }
                else {
                        $(this).parent().hover(function() 
                        // do something else when text is not 07 or 17 here
                       });
                }
	});

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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.