Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting the "type" attribute of an input does not work with jQuery attr() method
    primarykey
    data
    text
    <p>I looked into previous questions, but they didn't seem to answer what's happening to me.<br> In my real code i'm creating a form on the fly and adding to it two buttons, one for submission and another for other function. For this I'm setting the "type" attribute of the buttons to "submit" for one and "button" for the other. The problem is that in Chrome both buttons submit the form.</p> <p>Code for the form: </p> <pre><code>form = $(document.createElement('form')).attr('method', 'get').attr('action', defaults.action).appendTo(object); </code></pre> <p>Code for the buttons: </p> <pre><code>form.append( $(document.createElement('div')). attr('class', classesHash.buttonsContainer). append( $(document.createElement('button')). attr('type', 'submit'). addClass(classesHash.submitButton). attr('title', i18n('Filter')). attr('value', i18n('Filter')). append(i18n('Filter')) ). append( $(document.createElement('button')). attr('type', 'button'). addClass(classesHash.addButton). attr('title', i18n('Add filter')). attr('value', i18n('Add filter')). append(i18n('Add filter')). click(addFilter) ) ); </code></pre> <p>I made a more simple test with this HTML code:</p> <pre><code>&lt;form action="" method="get"&gt;&lt;button id="test"&gt;test&lt;/button&gt;&lt;/form&gt; </code></pre> <p>When Chrome doesn't finds a submit button, any button submits the form. </p> <p>The following doesn't works, the form gets submitted on button click:</p> <pre><code>$('#test').attr('type', 'button'); </code></pre> <p>The following does works, the form does not submit on button click:</p> <pre><code>document.getElementById('test').setAttribute('type', 'button'); </code></pre> <p>The form and the button are being generated dynamically and I'm using jQuery so attr() is the most obvious method. Is something wrong with the jQuery core and Chrome's JS specification? It works fine in Firefox. Thanks a lot.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload