javascript - how to set This in element input without tagging ID's -


5 input type, without tagging id's; if click input prompt command appear , enter name?; after entering name how can codes jquery of "this.value = person"...

<div class="lines">             <input type="text"><span>7-5</span></input>             <input type="text"><span>7-6</span></input>             <input type="text"><span>7-7</span></input>             <input type="text"><span>7-8</span></input>             <input type="text"><span>7-9</span></input> </div> 

then jquery are

$(document).ready(function(e){ var elementthis = $("input").click(function(){   var person = prompt("please enter name:");      if (person != null) {         this['input'] = person;        }       $(this).css("background-color","green"); }); }); 

please help. didn't input person = prompt on clickable inputs.

well slight modification here

demo

$(document).ready(function(e){     $("input").click(function(){         var that=$(this);//create reference         var person = prompt("please enter name:");         if (person) { //as per @roko c.buljan's suggestion            that.val(person);   //assign val            //or $(this) fine            that.css("background-color","green");//as per @roko c.buljan's suggestion            //you can move here in case cancel clicked         }      }); }); 

cancel validation demo

and yea no </input> @roko c.buljan said. <input> cannot have closing tag.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -