0

I have a view page and in which i applied a Jquery like

<script type="text/javascript">
$(document).ready(function () {
    var hdrname = $('#headername').text();
    alert(hdrname);

    if (hdrname == "Pending Assignment") {
        $('#lst1').addClass('highlight1');
        alert("hcsgiahf");
        $('#tab2').removeClass('highlight1');
    }
    else if (hdrname == "Assigned With L1 Support") {
        alert($('#tab1').text());
        alert("hello");
        $('#tab1').removeClass('highlight1');
        $("#tab2").addClass("highlight1");
    }

    //To get No of call start

});
//To get No of call end

But when i am running my page css class highlight1 is not applied on the specified id, can any1 help me why it happens..

6
  • Chances are the if conditions fail if the class isn't added Commented Jul 24, 2014 at 11:45
  • show you html as well Commented Jul 24, 2014 at 11:46
  • Are you getting alerts? Commented Jul 24, 2014 at 11:46
  • Run $('#tab1').removeClass('highlight1'); in the Chrome Dev tools console. Does it work then? Commented Jul 24, 2014 at 11:47
  • first trim your text like this var hdrname = $.trim($('#headername').text()) Commented Jul 24, 2014 at 11:48

1 Answer 1

1

Try

 if (hdrname == "Pending Assignment") {
    $('#tab1').addClass('highlight1');// i think you are wrong here
    alert("hcsgiahf");
    $('#tab2').removeClass('highlight1');
}
else if (hdrname == "Assigned With L1 Support") {
    alert($('#tab1').text());
    alert("hello");
    $('#tab1').removeClass('highlight1');
    $("#tab2").addClass("highlight1");
}

Your code works here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.