Javascript 将html附加到div的父级

Javascript 将html附加到div的父级,javascript,jquery,html,Javascript,Jquery,Html,我有以下代码: <div class="time-widget"> <select id="p_h_0_startHour_hour" name="" class="form-control select-time form-control"> <option value="0"> 00 </option> ........ </select>

我有以下代码:

<div class="time-widget">
    <select id="p_h_0_startHour_hour" name="" class="form-control select-time form-control">
        <option value="0">
          00
        </option>
        ........    
    </select>
</div
但是此html正在添加到选择框中,而不是在
时间小部件的前面。有什么建议吗?请提前通知。

更改
$('hello')。附加到('p#h"+i+'u startHour_hour')。parent()
$('hello')。插入之前($('p#h_uuu'+i+'u startHour_uhour')。parent()

必须将其附加到元素

演示

$('hello').insertBefore($('p#h_0_startHour_hour').parent()

00

你想要的是在
$(“#p#h#u+i+”\u startHour\u hour')
之前插入,因为
“#p#h#u+i+”
只是一个文本,你忘了把
$
放在前面,并且说你想把它放在前面(使用
insertBefore()
var i=0;
$('hello').insertBefore($('p#h#u'+i+'u startHour_hour').parent())

00
........    
使用

$('hello').insertBefore('time widget')

00

try
$('hello').appendTo($('p#h#h#u+i+'u startHour#h').parent()
可以删除在每个
insertBefore
之前添加的html。因为它是在每次调用时添加的,我有很多hello,但是ide应该有一个。谢谢,所以您想在运行代码之前删除
hello
?是的,因为实际上现在我在提交表单时调用此代码,如果表单有错误,请执行此插入操作,因此如果我多次单击submit,则会多次添加带有hello的div。请参见示例2
$('<div>hello</div>').appendTo('#p_h_'+i+'_startHour_hour').parent();