Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: <a id="#logout" href="#!/logout">Logout</a>

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that here.

Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: Logout

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that [here].

Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: Logout

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that here.

Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: Logout

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that here.

Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: Logout

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that here.

Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: Logout

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that here.

Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: Logout

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that here.

Silly mistake with jQuery and a CSS ID [Web Development]

I felt like I had to share this story! I was sitting at my desk, stumped, because I was trying to create a logout action for an app using the Facebook API and it seemed like my jQuery selectors were ignoring me. I double checked everything, did some back research on .live() and .on(). Did some more research on delegated events (since I was binding a click event to an element generated after the DOM loads). Nothing. I could NOT get it to work! I decided it might be because I was using an ID selector instead of a Class (you never know the weird things that can cause your program to break) and I noticed that I had the following code: <a id=&quot;&logout&quot; href=&quot;#!/logout&quot;>Logout</a>

Anybody catch my mistake? id="#logout" should NOT have a # sign in it! DOH! Still, it wasn't a total waste. I learned that .live() has been deprecated in favor of using .on() delegated events. You can read more about that here.

Firebug: SyntaxError: syntax error [Break On This Error]

Ran across this error in firebug after changing around the directory structure of one of our client's landing pages.



It's a very poorly worded and generic error message.

Obviously the doctype doesn't have a syntax error..

So what does it mean?
Some of the Javascript files on the page had invalid SRC urls.

Check the URLs to your JS files on the page and the error will disappear.

Although it does mention the JS file that's missing, it makes it seem like the missing JS file is being loaded and has an issue on its first line.

Confusing?

 

Did this help you? Let me know in the comments!

Firebug: SyntaxError: syntax error [Break On This Error]

Ran across this error in firebug after changing around the directory structure of one of our client's landing pages.

It's a very poorly error message.

Obviously the doctype doesn't have a syntax error..

So what does it mean?
Some of the Javascript files on the page had invalid SRC urls.

Check the URLs to your JS files on the page and the error will disappear.

Firebug: SyntaxError: syntax error [Break On This Error]

Ran across this error in firebug after changing around the directory structure of one of our client's landing pages.

It's a very poorly error message.

Obviously the doctype doesn't have a syntax error..

So what does it mean?
Some of the Javascript files on the page had invalid SRC urls.

Check the URLs to your JS files on the page and the error will disappear.

Firebug: SyntaxError: syntax error [Break On This Error]

Ran across this error in firebug after changing around the directory structure of one of our client's landing pages.

It's a very poorly worded and generic error message.

Obviously the doctype doesn't have a syntax error..

So what does it mean?
Some of the Javascript files on the page had invalid SRC urls.

Check the URLs to your JS files on the page and the error will disappear.

Firebug: SyntaxError: syntax error [Break On This Error]

Ran across this error in firebug after changing around the directory structure of one of our client's landing pages.

It's a very poorly worded and generic error message.

Obviously the doctype doesn't have a syntax error..

So what does it mean?
Some of the Javascript files on the page had invalid SRC urls.

Check the URLs to your JS files on the page and the error will disappear.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
[html]
<div class="inputBG" align="center">
<input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" />
</div>
[/html]
This is a no-no.

Instead, use this:

HTML

[html]<input id="name" type="text" name="name" placeholder="placeholder name">[/html]

 jQuery

[javascript]
// only necessary for browsers that don't support the placeholder attribute
$(document).ready(function(){
$('input').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
});

$('input').on({
'click': function(){ // clear the placeholder
if( $(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
},
'blur': function(){ // reset the placeholder
if( $(this).val() == ''){ $(this).val($(this).attr('placeholder')); }
}
});
[/javascript]

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
[html]<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>[/html]
This is a no-no.

Instead, use this:

HTML

[html]<input id="name" type="text" name="name" placeholder="placeholder name">[/html]


 jQuery

[javascript]
// only necessary for browsers that don't support the placeholder attribute
$(document).ready(function(){
$('input').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
});

$('input').on({
'click': function(){ // clear the placeholder
if( $(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
},
'blur': function(){ // reset the placeholder
if( $(this).val() == ''){ $(this).val($(this).attr('placeholder')); }
}
});
[/javascript]

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
[html]&lt;div class="inputBG" align="center"&gt;&lt;input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /&gt;&lt;/div&gt;[/html]
This is a no-no.

Instead, use this:

HTML

[html]&lt;input id="name" type="text" name="name" placeholder="placeholder name" /&gt;[/html]


 jQuery

[javascript]
// only necessary for browsers that don't support the placeholder attribute
$(document).ready(function(){
$('input').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
});

$('input').on({
'click': function(){ // clear the placeholder
if( $(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
},
'blur': function(){ // reset the placeholder
if( $(this).val() == ''){ $(this).val($(this).attr('placeholder')); }
}
});
[/javascript]

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.

Instead, use this:

HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
$(document).on('load', function(){
$('input[type=text]').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
}

$('input').on('click',function(){
if($(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
});

And all is good and right in the world.

I'm assuming you have a basic understanding o

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.

Instead, use this:

HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
$(document).on('load', function(){
$('input[type=text]').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
}

$('input').on('click',function(){
if($(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
});

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.

Instead, use this:

HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
$(document).on('load', function(){
$('input[type=text]').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
}

$('input').on('click',function(){
if($(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
});

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.

Instead, use this:

HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
[javascript]
// only necessary for browsers that don't support the placeholder attribute
$(document).ready(function(){
  $('input').each(function(i,v){
    // set initial values
    $(this).val($(this).attr('placeholder'));
  });
});

$('input').on({
    'click': function(){ // clear the placeholder
        if( $(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
     },
    'blur': function(){ // reset the placeholder
        if( $(this).val() == ''){ $(this).val($(this).attr('placeholder')); }
    }
});
[/javascript]
And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.

Instead, use this:

HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
$(document).on('load', function(){
$('input[type=text]').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
}

$('input').on('click',function(){
if($(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
});

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.

Instead, use this:

HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
// only necessary for browsers that don't support the placeholder attribute
$(document).on('load', function(){
$('input[type=text]').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
}

$('input').on('click',function(){
if($(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
});

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
<div class="inputBG" align="center"><input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" /></div>

This is a no-no.

Instead, use this:

HTML
<input id="name" type="text" name="name" placeholder="placeholder name" />

 jQuery
// only necessary for browsers that don't support the placeholder attribute
$(document).ready(function(){
  $('input').each(function(i,v){
    // set initial values
    $(this).val($(this).attr('placeholder'));
        console.log($(this).val());
  });
});
 
$('input').on({
    'click': function(){
        if( $(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
     },
    'blur': function(){
        if( $(this).val() == ''){ $(this).val($(this).attr('placeholder')); }
    }
});

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.

Firebug: SyntaxError: syntax error [Break On This Error]

Ran across this error in firebug after changing around the directory structure of one of our client's landing pages.



It's a very poorly worded and generic error message.

Obviously the doctype doesn't have a syntax error..

So what does it mean?
Some of the Javascript files on the page had invalid SRC urls.

Check the URLs to your JS files on the page and the error will disappear.

Although it does mention the JS file that's missing, it makes it seem like the missing JS file is being loaded and has an issue on its first line.

Confusing?

 

Did this help you? Let me know in the comments!

Simple placeholder text for input fields using jQuery

Today I came across a form using inline javascript events for placeholders:
[html]
<div class="inputBG" align="center">
<input name="company" id="company" type="text" placeholder="Company Name" onBlur="if (this.value == '') {this.value = 'Company Name';}" onFocus="if (this.value == 'Company Name') {this.value = '';}" />
</div>
[/html]
This is a no-no.

Instead, use this:

HTML

[html]<input id="name" type="text" name="name" placeholder="placeholder name">[/html]

 jQuery

[javascript]
// only necessary for browsers that don't support the placeholder attribute
$(document).ready(function(){
$('input').each(function(i,v){
// set initial values
$(this).val($(this).attr('placeholder'));
});
});

$('input').on({
'click': function(){ // clear the placeholder
if( $(this).val() == $(this).attr('placeholder')){ $(this).val(''); }
},
'blur': function(){ // reset the placeholder
if( $(this).val() == ''){ $(this).val($(this).attr('placeholder')); }
}
});
[/javascript]

And all is good and right in the world.

I'm assuming you have a basic understanding of document structure and how to implement jQuery.

If you have any questions, please ask.