0

Trying to get to work this bit of a code

<script type="text/javascript">
$(function (){
    if ( document.location.href.indexOf('product') > -1){
    $('.featproducts').addClass("display-none")
}
});
</script>

The URL is: http://domsveta.by/katalog/product/3919-

Here's some test fiddle http://jsfiddle.net/83H63/5/

I'm afraid it's in Russian so it's gonna create some complecations in understanding.

Any idea why it doesn't work? Thanks

I want to assign a class .display-none to any the element of class "featproducts" if it is shown on the page with "product" in the URL

UPDATE

In the fiddle http://jsfiddle.net/83H63/5/ Using the # I was able to add a class to an element

However on the production site I wasn't able to do it using either # or .featproducts

So it's not the code that's faily.

Thank you for your heads up.

cameraobscura
  • 177
  • 1
  • 2
  • 17

3 Answers3

0

class selector .

$('.featproducts').addClass("display-none");
// ^
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
0

You need to use . to target class in jQuery, so you can do:

$('.featproducts').addClass("display-none");
Felix
  • 37,892
  • 8
  • 43
  • 55
0

Gosh! how could I not see it...

Demo: JSFiddle Ignore the alert, hit "run"

it has to be:

window.location.href


if ( window.location.href.indexOf('product') > -1){
    $('.featproducts').addClass("display-none")
}
lshettyl
  • 8,166
  • 4
  • 25
  • 31
  • 1
    According to the W3C, they are the same. In reality, for cross browser safety, you should use window.location rather than document.location see:http://stackoverflow.com/questions/2430936/whats-the-difference-between-window-location-and-document-location-in-javascrip – Vickel Mar 22 '14 at 17:29