2017-11-02 21 views
0

私はこのように作成した入力フィールドを持っています。入力タグの隣にdivを追加する方法

var inputVal = document.createElement("input"); 

inputVal.setAttribute("type", "checkbox"); 
inputChek.onchange = select; 
inputChek.setAttribute("value", title); 

//inputChek.after(sortDiv); 
docClass.prepend(inputChek); 
docClass.append(newDiv); 

矢印の画像をテキストの直後に追加したいが、表示されない。 divは作成されていますが、ダウンしています。

var newDiv = document.createElement("div"); 

newDiv.setAttribute("class", "Arrow"); 
//sortDiv.style.display = ' transform: rotate(45deg), webkit-transform: rotate(45deg);'*/ 
newDiv.setAttribute("onclick",'divClick("title")'); 
newDiv.style.background = "red"; 
newDiv.style.width = "10px"; 
newDiv.style.height = "10px"; 

ここに画像があります。

テキストを後ろに追加します。 enter image description here この問題の解決方法あなたが望むようにここで

+0

インライン何かを追加したい場合なぜdiv(==ブロック要素)を使用してスパンではないのですか? – cloned

+0

ここでは「span」を使用する必要があります – David

+0

はい、spanにはインライン表示があり、divにはブロック表示(css wise)があります。 コードを変更します。var newDiv = document.createElement( "div"); => var newSpan = document.createElement( "span");残りのコードを更新します。 –

答えて

0

は、それはあなたが変更(スタイル)ができ
、入力後div要素を追加する方法の基本的な例です。

var root = document.getElementById("root"), 
 
    checkbox = document.createElement("input"), 
 
    block = document.createElement("div"); 
 

 
checkbox.type = "checkbox"; 
 
checkbox.value = "title"; 
 

 
block.className = "arrow"; 
 
block.setAttribute("onclick",'divClick("title")'); 
 
block.style.background = "red"; 
 
block.style.display = "inline-block"; 
 
block.style.width = "36px"; 
 
block.style.height = "12px"; 
 

 
root.appendChild(checkbox); 
 
root.appendChild(block); 
 

 
function divClick(text){ 
 
    console.log('you had just clicked the ' + text); 
 
}
<div id="root" class="form-group"></div>

関連する問題