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
  • 319,460
  • 37
  • 290
  • 318
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
  • 27,939
  • 1
  • 46
  • 46
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
  • 36,631
  • 8
  • 65
  • 95