locked
Is there a way to make this a variable RRS feed

  • Question

  • User-131059102 posted

    is there a way to make $("js-page-alerts") into a variable?

    <script>
        $(document).ready(function () {
            if ($(".js-page-alerts") != null || $(".js-page-alerts") != "undefined") {
                if ($.trim($(".js-page-alerts").text()).length > 10) {
                    $(".ins-alert").css("display", "inherit");
                }
            }
        });
    </script>  

    Thanks

    Thursday, February 18, 2016 8:46 PM

Answers

  • User2103319870 posted

    is there a way to make $("js-page-alerts") into a variable?

    You can try with the below code

     <script>
            $(document).ready(function () {
                var pgalert = $(".js-page-alerts");
    
                if (pgalert != null || pgalert != "undefined") {
                    if ($.trim(pgalert.text()).length > 10) {
                        $(".ins-alert").css("display", "inherit");
                    }
                }
            });
    </script>  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 18, 2016 9:00 PM

All replies

  • User2103319870 posted

    is there a way to make $("js-page-alerts") into a variable?

    You can try with the below code

     <script>
            $(document).ready(function () {
                var pgalert = $(".js-page-alerts");
    
                if (pgalert != null || pgalert != "undefined") {
                    if ($.trim(pgalert.text()).length > 10) {
                        $(".ins-alert").css("display", "inherit");
                    }
                }
            });
    </script>  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 18, 2016 9:00 PM
  • User1633621018 posted

    Hi,

    Are you trying to check the existence of element? try using .length

    if($(".js-page-alerts").length)
    {}

    Thursday, February 18, 2016 9:43 PM
  • User61956409 posted

    Hi sayitfast,

    is there a way to make $("js-page-alerts") into a variable?

    We declare a JavaScript variable with the var keyword.

    http://www.w3schools.com/js/js_variables.asp

    Best Regards,

    Fei Han

    Friday, February 19, 2016 5:29 AM