How do I check if a specific text input in a form is selected (highlighted)? Can I do it with jQuery?
            Asked
            
        
        
            Active
            
        
            Viewed 2,284 times
        
    0
            
            
        - 
                    possible duplicate [http://stackoverflow.com/questions/4712310/javascript-how-to-detect-if-a-word-is-highlighted](http://stackoverflow.com/questions/4712310/javascript-how-to-detect-if-a-word-is-highlighted) – Amit.rk3 Jul 19 '15 at 08:53
4 Answers
0
            
            
        You can use this
input:focus { 
    background-color: yellow;
}
 
    
    
        abs
        
- 801
- 6
- 15
- 
                    Please consider adding at least some words explaining to the OP and to further readers of you answer why and how it does reply to the original question. – β.εηοιτ.βε Jul 19 '15 at 10:02
0
            
            
        Try this:
var selected = $(':focus');
 
    
    
        monkey
        
- 1,279
- 14
- 15
- 
                    
- 
                    
- 
                    
- 
                    Please consider adding at least some words explaining to the OP and to further readers of you answer why and how it does reply to the original question. – β.εηοιτ.βε Jul 19 '15 at 10:04
0
            
            
        Since you only want input types text. Here is a javascript solution.
function addevents() {
   var input = document.getElementsByTagName('input');
   for(var i=0;i<input.length;i++) {
      input[i].addEventListener('focus', focus, false);
}
function focus() {
    if(this.type === 'text')
        alert(this + ' iam a text input');
}
addevents();
0
            
            
        You can get selected input text using following jQuery statement:
$("input[type='text']:focus")
 
    
    
        marc_s
        
- 732,580
- 175
- 1,330
- 1,459
 
    
    
        Sachin Chandil
        
- 17,133
- 8
- 47
- 65
