0

There might be a really simple solution to this question, but i just don't see it!

I have a page with a list of items. every item has the same jquery ui button (its inside a dialog and adds that item to a list). i identify the item via the parenting DIV holding the DB id. So far so good...

The Problem is only the first button on the list works! The second, third etc. buttons don't show any reaction at all. The buttons all have the same id - as the list is dynamic and the same action is triggered with every click. Only the parenting ID changes.

Heres the display part:

<div id="2">
  <div id="56">
    <button id="add-audio-file" class="ui-button ui-state-default ui-corner-all">betty_2.mp3</button>
  </div>
</div>

<div id="2">
  <div id="57">
    <button id="add-audio-file" class="ui-button ui-state-default ui-corner-all">betty_3.mp3</button>
  </div>
</div>

And here comes the js Part:

    $('#add-audio-file').click(function() {
        assetID = $(this).parent('div').attr('id');
        pageID = $(this).parent('div').parent('div').attr('id');
        $.post(
            "modules/portfolio/serialize.php", 
            {id : pageID, assetid : assetID, do : "add-audio-file"},
                function(data, textStatus, xhr) {
                    $('#dialog-add-audio').dialog('close');
                }
        );

    });

I am using jquery 1.4.2 and jquery ui 1.8rc3 Any ideas?

3 Answers 3

9

The buttons all have the same id

id is identifier for an element, you can not set that for more than one element. Try giving your buttons class instead and see if it works after that.

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

Comments

2

Aren't duplicate ID's in a document bad practice?

Comments

0

This will work when you put button element

in html:

<input type="button" value="MyButton1" /> 
<input type="button" value="MyButton2" />
...
<input type="button" value="MyButtonN" />

in javascript of jquery-ui:

search for: $("#button").button(); 
then replace or add    $('[type="button"]').button();"

ex

$("#button").button();
$('[type="button"]').button();

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.