[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check if an element is defined

Posted on 2009-04-27
3
Medium Priority
?
331 Views
Last Modified: 2012-05-06
I have this code...

        var portfolio_item = $$('.portfolio_item');

Following is a bunch of stuff manipulating items within this  item, but if the item is not defined on the page, I want it to skip that stuff.
How can I do an if statement that makes sure this item is even on the page first?
0
Comment
Question by:Starr Duskk
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Pawel Witkowski earned 2000 total points
ID: 24244686
var portfolio_item = $$('.portfolio_item');
if (portfolio_item)
{

}


tried that?
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 24244734
Thanks!
Everything I was reading was saying to check the length...
http://www.kavoir.com/2009/04/jquery-how-to-test-or-check-whether-an-element-exists.html
if ($("#some").length)
http://jqueryfordesigners.com/element-exists/
$('element').length == 0;
And that errored.
Thanks again! Yours works!
 
 
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 31575072
great!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question