jQuery and label input
<div id="one">
<label for="number">Number</lab开发者_JAVA技巧el>
<div id="two">
<input id="number" type="text" name="number">
</div>
</div>
This show me:
- Number
- [input]
How can I make:
- Number [input]
How can I modify this with jQuery? (not modify html)
LIVE: http://jsfiddle.net/UBx6p/
Use a <span>
instead of a <div>
.
<div id="one">
<label for="number">Number</label>
<span id="two">
<input id="number" type="text" name="number">
</span>
</div>
Well, you really should change the HTML as stated above by Xavi.
If that is out of the question, you can perform the HTML changes via jQuery:
$('#one label').css('float', 'left');
$('#one #two').css('float', 'left');
$('#one #two').css('margin-left', '5px');
$('#one').append('<div style="clear:both"></div>');
put it here : http://jsfiddle.net/UBx6p/8/
Can you use CSS rather than javascript?
#two {
display:inline-block;
}
If you want it only in JS. Then as suggested use something like this
document.getElementById('two').style.display = 'inline';
精彩评论