javascript - JQuery .replaceWith() suddenly putting new element in the wrong place? -



javascript - JQuery .replaceWith() suddenly putting new element in the wrong place? -

this 1 baffling me. i'm using replacewith() "clear" file input field. however, when replaces it, puts in wrong place, , have no thought why. used term "suddenly" in title because what's more mysterious when stopped working weekend replacement working expected. work , it's not.

here's source html before calling replacewith():

<label>audio</label> <i style="color:#888888;">mp3 or ogg format recommended</i> <br> <button id="clear_audio_input" style="display:none;">clear</button> <input type="file" value="" name="source_audio" style="width:300px;"> <br> <div style="margin-top:15px;"> <b>current: </b> <i id="current_audio_source">1360954394_121ruleofrosepianoetudei.mp3</i> <br> <input id="source_audio_value" class="required_media" type="hidden" value="1360954394_121ruleofrosepianoetudei.mp3" name="source_audio"> <span id="current_audio_info_a"><input type="checkbox" style="position:relative;top:3px;margin-left:0px;" value="yes" name="source_audio_delete">

delete current audio? current sound replaced

note location of file input field, named "source_audio". it's after "clear" button.

now, after phone call replacewith(), html looks this:

<label>audio</label> <i style="color:#888888;">mp3 or ogg format recommended</i> <br> <button id="clear_audio_input" style="display: none;">clear</button> <br> <div style="margin-top:15px;"> <b>current: </b> <i id="current_audio_source">1360954394_121ruleofrosepianoetudei.mp3</i> <br> <input type="file" value="" name="source_audio" style="width:300px;"> <input id="source_audio_value" class="required_media" type="hidden" value="1360954394_121ruleofrosepianoetudei.mp3" name="source_audio"> <span id="current_audio_info_a" style="display: inline;"><input type="checkbox" style="position:relative;top:3px;margin-left:0px;" value="yes" name="source_audio_delete">

delete current audio? current sound replaced

notice several lines downwards , within div.

here script controls "clear" button's actions:

$("#clear_audio_input").live("click", function() { $("input[name='source_audio']").replacewith($("input[name='source_audio']").val('').clone(true)); $("#source_audio_value").val($("#current_audio_source").text()); $(this).hide(); $("#current_audio_info_a").show(); $("#current_audio_info_b").hide(); checkrequiredmedia(); homecoming false; });

here's basic intended workflow. on load, clear button hidden because there nil yet clear. after user has selected file, clear button appears. clicking button clear file input (by replacing it) , button hide again, returning form same state in on load.

any reason why oddity happening (especially since wasn't happening few days ago, , haven't changed since then)?

the issue because have 2 inputs name source_audio. around this, need either give 2 inputs fields id, or alter name.

for example:

$('#my_file_input').replacewith('<input id="my_file_input" type="file" name="source_audio" />'); $('#my_hidden_file_input').val('');

javascript jquery file input replacewith

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -