If you observe the error:
Syntaxerror: Missing ) after argument list
That translates:
Syntax error: Missing )
after the list of arguments
Ability to understand, with the help of indicating the line where the error occurred, that the parentheses of the method have to be closed .ready()
, which takes as an argument a function to be executed 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
Optimizing
Taking advantage of the answer, there is a tip to minimize the interaction with the DOM since you make several calls to the elements in the 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 improve two things:
Avoid always searching for the element in .focus()
or .blur()
caching:
var $this = $(this);
Hide multiple elements at once avoiding multiple lines of code for the same purpose:
$( ".soluctionsDescriptionShow, .soluctionsApplicationsShow" ).hide();
Thank you very much! Hours in front of the computer generate these carelessness, eheh.
– Felipe Viero Goulart