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.

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();
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.