-1

I use some jQuery code to modify style of an H1 element like this:

jQuery(window).on('load', function() {            
  $('h1').css('text-transform', 'lowercase');
});

but I want to exclude some element with a precise class of that, so I try to change my code this way, with no results:

jQuery(window).on('load', function() {
  //Changer la casse des titres H1 qui sont en Majuscules
  if ($('h1').hasClass('.vdl_titre')) {
    $('h1').css('text-transform', 'inherit');
  } else {
    $('h1').css('text-transform', 'lowercase');
  }
});

So help is needed :) thanks

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
webmaster pf
  • 389
  • 1
  • 5
  • 23
  • As rightly pointer out by @[gurvinder372](https://stackoverflow.com/users/1984039/gurvinder372), removing dot(`.`) would solve the issue. Dot represents class but in selector and there can be different combinations, hence you need this identifier. `hasClass` checks for availability of class only, so it expects name as string without any identifier. Please check **[docs](https://api.jquery.com/hasclass/)** before using. – Rajesh Nov 20 '17 at 13:32
  • *exclude some element* for this, you can use `not` selector. Try `$('h1:not(.vdl_titre)').css(...)` – Rajesh Nov 20 '17 at 13:36
  • Refer this for more information: https://stackoverflow.com/questions/3015103/jquery-exclude-elements-with-certain-class-in-selector – Rajesh Nov 20 '17 at 13:41

1 Answers1

0

You need to use has class like this:

hasClass("vdl_titre")
Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95
Rajesh Grandhi
  • 378
  • 3
  • 13