Get the Adjecent Element type

Discussion in 'jQuery' started by theextelligence, Feb 23, 2012.

  1. #1
    Hi

    I have the following DOM structure and I want to know if the Adjecent Element of the selected checkbox is a "text" type element or not..

    
    <ul>
    	<li>
    		<label><input type="checkbox">AA:</label>
    			<ul>
    				<li><label><input type="checkbox" id="bb">BB:</label><input type="text"></li>
    				<li><label><input type="checkbox">CC:</label><input type="radio"></li>
                                   <li><label><input type="checkbox" id="dd">DD:</label><input type="text"></li>
    			</ul>
    	</li>
    </ul>
    
    Code (markup):
    I am using the following jQuery code

    
    
    $('input[type=checkbox]').bind('click change', function(){
    
      var getElementType = $(this + ' + input').attr('type');
      console.log(getElementType);    
    
    
    });
    
    
    Code (markup):

    but getting this error:
    uncaught exception: Syntax error, unrecognized expression: [object HTMLInputElement]

    In the above DOM structure, it should be for the chekboxes with id "bb" and "dd",


    can someone please help me with this?

    Thanks
     
    theextelligence, Feb 23, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    There is no "adjacent element". Use class or some other property to differentiate your check boxes.
     
    Rukbat, Feb 25, 2012 IP