0

Hey, how's it goin

I'm trying to write a simple if statement with jQuery...it looks like this

if ($('#title .general').length == 0) {
     function() {
	$('#ubi').empty();
	$('#address').empty();
	$('#city').empty();
	$('#region').empty();	
     }
}

First off, i'm getting an error in firefox that has

"syntax error"
function( ) { }
-----------^

Second, I have some elements that are to be hidden and then made visible after certain things happen on the page, but once I introduce this if statement, all elements appear visible on document ready, as if all the code after the if statement that pertains to those elements is invalidated. Err...what the if!

So I believe I need to pass in a parameter? I'm not sure what that would need to be, i'm kind of cloudy on the idea of parameters for some reason. Anyone able to point me in the right direction?

Mucho gracias.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by seniramsu
0

You can't define a function within a conditional statement.

You would do this:

function empty_fields() {
	$('#ubi').empty();
	$('#address').empty();
	$('#city').empty();
	$('#region').empty()
}

if ($('#title .general').length == 0) {
	empty_fields();
}

Edited by pwinfrey: n/a

0

Ok great, thanks! Unfortunately my problem extends further than just the correct syntax of the if statment.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.