Sangram Singh
Sangram Singh

Reputation: 7191

Chosen jQuery plugin not functional.

Using Chosen version 1.0.0 I included the following files

link(href='css/chosen.css', rel="stylesheet", type="text/css");
script(src='js/chosen.jquery.min.js')
script.
    $(".chosen-select").chosen()

body
  select(data-placeholder="Choose a country...", multiple style="width:350px;" ).chosen-select
            <option value=""></option>
            <option value="United States">United States</option>
            <option value="United Kingdom">United Kingdom</option>
            <option value="Afghanistan">Afghanistan</option>
            <option value="Aland Islands">Aland Islands</option>
            <option value="Albania">Albania</option>
            <option value="Algeria">Algeria</option>
            <option value="American Samoa">American Samoa</option>

The above code gives a disfunctional select box The above display is same as

select(multiple, style="width:350px;")
            <option value=""></option>
            <option value="United States">United States</option>

Upon analysis I see, that both chosen.css and chosen.jquery.min.js have no class chosen-select I am using jQuery version v1.10.2 Also I am loading jQuery as the first file on the page to avoid conflict.

Thanks for helping.

Upvotes: 1

Views: 14678

Answers (3)

Sam N
Sam N

Reputation: 1

This can sometimes happened because the confliction of the jquery library. Define your JavaScript inside no conflict. https://api.jquery.com/jquery.noconflict/

Upvotes: 0

Fawad
Fawad

Reputation: 43

Mine doesn't worked instead it worked by

<script type="text/javascript" src="js/chosen.jquery.js" >
</script>   
<script>
    `Enter only enter chosen related code here`
</script>

Upvotes: 0

Sangram Singh
Sangram Singh

Reputation: 7191

Adding

script.
        $(document).ready(function(){
            $(".chosen-select").chosen()
        });

Instead of just $(".chosen-select").chosen() makes it work!

Upvotes: 6

Related Questions