1

For some reason, this isn't launching

<script type="text/javascript">
$(function(){
if ($(h3).hasClass("6") ){
alert ('Todays Date Friday')  }
});
</script>
gen_Eric
  • 214,658
  • 40
  • 293
  • 332
Spanky
  • 689
  • 1
  • 11
  • 34

1 Answers1

5
$(h3)

supposed to be

$('h3') // Missing the quotes

If you want your selector to work, you can assign the variable name.

var h3 = 'h3'; // This should   work as well
if ($(h3).hasClass("6") ){
Sushanth --
  • 54,565
  • 8
  • 62
  • 98
  • 2
    This. And as for the class called `6`, read: http://stackoverflow.com/a/449000/684932 CSS classes can't start with number. – RaphaelDDL Aug 09 '13 at 20:40
  • 1
    @RaphaelDDL.. It is not essentially invalid. But it is a better practice to avoid using class names that start with a number – Sushanth -- Aug 09 '13 at 20:42
  • 1
    @RaphaelDDL Yes they can. People just need to learn how to use selectors properly – Ian Aug 09 '13 at 20:43
  • 2
    @RaphaelDDL [I would disagree](http://stackoverflow.com/questions/9210307/html-5-classnames-and-ids). – Vucko Aug 09 '13 at 20:44
  • Having a class name starting with a number is valid `HTML` , but the styles might not be added for such cases using `CSS` – Sushanth -- Aug 09 '13 at 20:44
  • Forgot HTML5 removed that HTML4/xHTML restriction. Thanks everyone. – RaphaelDDL Aug 09 '13 at 20:46
  • 1
    @Sushanth-- There should be no problem having styles added, they just need to be escaped. http://jsfiddle.net/JszJ9/ – Ian Aug 09 '13 at 20:47