If you notice the error:
SyntaxError: missing) after argument list
What translated is:
Syntax error: Missing )
after argument list
To understand, with the help of the indication of the line where the error occurred, you have to close the parentheses of the method .ready()
, whose argument is given a function to execute after the DOM is available.
Rectified code
$(document).ready(function(){
$('input[placeholder], textarea[placeholder]').focus(function(){
if($(this).val()==$(this).attr('placeholder'))
$(this).val('');
}).blur(function(){
if($(this).val()=='')
$(this).val($(this).attr('placeholder'));
});
$( ".soluctionsBenefits" ).click(function() {
$( ".soluctionsBenefitsShow" ).show();
$( ".soluctionsDescriptionShow" ).hide();
$( ".soluctionsApplicationsShow" ).hide();
});
}); // Faltava fechar os parênteses aqui
Optimization
Taking advantage of the answer, here's a hint to minimize interaction with the DOM because you make several calls to elements in methods .focus()
and .blur()
:
$(document).ready(function(){
$('input[placeholder], textarea[placeholder]').focus(function(){
// colocar elemento em cache para evitar andar sempre a procurar o mesmo
var $this = $( this );
if ( $this.val()==$this.attr('placeholder') )
$this.val('');
}).blur(function(){
var $this = $( this );
if ( $this.val()=='' )
$this.val( $this.attr('placeholder') );
});
$( ".soluctionsBenefits" ).click(function() {
$( ".soluctionsBenefitsShow" ).show();
// esconder vários elementos ao mesmo tempo
$( ".soluctionsDescriptionShow, .soluctionsApplicationsShow" ).hide();
});
});
Essentially, we've improved two things:
Avoid always looking for the element in .focus()
or .blur()
by caching it:
var $this = $(this);
Hide multiple elements at once by avoiding multiple lines of code for the same effect:
$( ".soluctionsDescriptionShow, .soluctionsApplicationsShow" ).hide();