tags:

views:

45

answers:

3

Hello,

I cannot target an element in jQuery.

First example which works :

$(document).ready(function()
{
    $('#Models').hide();
});

Second example which fails :

    $(document).ready(function()
    {
       $('#Make').bind('change',function()
       {
          $('#Models').hide();          
       });
    });

In this case, the "#Models" isn't hide at all. I cannot find any good solution. Is there any scoping issue ?

Thanks for any help or any clue!

This is a part of my code :

    <div class="search-row">
        <div class="search-flag">
        </div>
        <select id="Make" name="Make">
            <option value="">Marque</option>
            <?
            $marques = Marque::getList();
            foreach($marques as $m) {
            ?>
                <option value="<?=$m?>"><?=$m?></option>
            <? } ?>
        </select>
    </div>
    <br class="clear" />
    <div class="search-row">
        <div class="search-flag">
        </div>
        <script type='text/javascript'>
        $(document).ready(function()
        {
            $('#Make').change(function()
            {
                alert("test");
                $('#Models').hide();
            });           
        });
        </script>

        <select name="Models_name" id="Models">
            <option value="all">
                All
            </option>
        </select>
    </div>

(I only have one id called "Models" in all my code)

A: 

That looks like it should work - are you sure the '#Make' ID exists?

Give this a try:

$('#Make').change(function() {
  alert('change event!');
  $('#Models').hide(); 
});
xil3
I try your code but only the alert is happening.
Boun
Do you have more than one <select> using the ID 'Models'?
xil3
No I only have one "Models" id.
Boun
A: 

Seems like the change handler of #Make is never triggered. What element type is #Make?

JochenJung
This should have been posted as a comment.
GenericTypeTea
#Make is a <select> element.
Boun
Given his rep he may well not have been able to post it as a comment when he made it. Its an annoying thing about being a new user but at least it doesn't last long... :)
Chris
I finally found the problem.In fact, I'm working on an existing project and I don't catch every subtilities that have been using.I find out that all select tag by default are invisible and in fact, there are another select menu loaded by some jQuery.Since the start, every code written in my Question is working good.Thank you all of you to help me. Next time, I'll check all my codes before disturbing all of you.
Boun
A: 

Can it be a caching issue? Your code runs fine here... Try checking the current html version, inspecting its source...

Rodrigo Gama
As a last resource, if this is not the case, try to post the whole generated HTML, and we can take a look.
Rodrigo Gama
You may be right, I try this part of code in a new test page and everything goes right so the problem may come from the HTML. So now I check the HTML and I'll tell everyone about this.
Boun