开发者

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:

  1. Number
  2. [input]

How can I make:

  1. 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'; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜