[SalesForce] Jquery not running on visualforce Page

I am not adding it through a separate vf resource even.

I am directly writing HTML on the page.

<script>
$.noConflict();
(function($){
    function floatLabel(inputType){
        $(inputType).each(function(){
            console.log("jQ Running");
            var $this = $(this);
            // on focus add cladd active to label
            $this.focus(function(){
                $this.next().addClass("active");
                console.log("jQ active added");
            });
            //on blur check field and remove class if needed
            $this.blur(function(){
                if($this.val() === '' || $this.val() === 'blank'){
                    $this.next().removeClass();
                    console.log("jQ active removed");
                }
            });
        });
    }
    // just add a class of "floatLabel to the input field!"
    floatLabel(".floatLabel");
})(jQuery);
</script>

it does not work at all.

anyone know why?

Best Answer

solved it.

it was pretty basic.

but now works. thanks guys. and it never even loaded by console values.

thanks.

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" />
<script>
var j$ = jQuery.noConflict();
j$(document).ready(function(j$){
    function floatLabel(inputType){
        j$(inputType).each(function(){
            console.log("jQ Running");
            var j$this = j$(this);
            // on focus add cladd active to label
            j$(this).focus(function(){
                j$(this).next().addClass("active");
                console.log("jQ added active class");
            });
            //on blur check field and remove class if needed
            j$(this).blur(function(){
                if(j$(this).val() === '' || j$(this).val() === 'blank'){
                    j$(this).next().removeClass();
                    console.log("jQ removed active class");
                }
            });
        });
    }
    // just add a class of "floatLabel to the input field!"
    floatLabel(".floatLabel");
})(jQuery);
</script>
Related Topic