0

I am having a code in _layout.cshtml.

@if (TempData["SuccessMessage"] != null)
{
    <div class="alert alert-success">
        @TempData["SuccessMessage"];
    </div>
}

And in javascript

$(function() {
    $(".alert alert-success").fadeOut("slow");
});

But the div is not fading out. Please suggest what I am doing wrong.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Yogendra Singh
  • 169
  • 1
  • 1
  • 10

2 Answers2

2

jQuery Docs - Class Selectors has an example that is quite relevant (Finds the element with both "myclass" and "otherclass" classes.)

Try changing:

$(function () {
  $(".alert alert-success").fadeOut("slow");
});

To:

$(function () {
  $(".alert.alert-success").fadeOut("slow");
});

or you could try .filter():

$(".alert").filter(".alert-success")

However, this method will be slightly slower since you are first compiling a set of all match .alert elements and then filtering those to compile a second set or those containing .alert-success.

Find more info in a similar post here

Community
  • 1
  • 1
Chase
  • 29,019
  • 1
  • 49
  • 48
1

this are two classes alter and alert-success so you need to do

$(".alert.alert-success").fadeOut("slow");

OR

$(".alert-success").fadeOut("slow");

OR

$(".alert").fadeOut("slow");
t.niese
  • 39,256
  • 9
  • 74
  • 101