-2

I can't figure out what's wrong with my jquery, i'm trying to do a Content slider but my .first() can't filter my first class for some reason.

A sample of what im talking about

jQuery

 1. $('.textinside').first().addClass('active');

CSS

.active{
   display: block;
}
.textinside{
   color: blue;
   font-size: 19px;
   background-color: black;
   position: absolute;
   display: none;
}

html

<div class="container">

<div class="textinside">text1</div>
<div class="textinside">text2</div>
<div class="textinside">text3</div>
</div>
Rob
  • 14,746
  • 28
  • 47
  • 65
  • 3
    What makes you think that the `first` method is the problem? I'm pretty sure it isn't. Make sure you have loaded the jQuery library and the elements have been added to DOM before executing that line. – Ram Nov 01 '15 at 18:54

1 Answers1

1

Swap the two classes in your CSS file. The second one overwrites the first. So use:

.textinside{
   color: blue;
   font-size: 19px;
   background-color: black;
   position: absolute;
   display: none;
}

.active {
   display: block;
}

and it will work. Demo: http://jsfiddle.net/bcexLgvd/

Reeno
  • 5,720
  • 11
  • 37
  • 50