jQuery Get the Adjecent Element type

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>

I am using the following jQuery code



$('input[type=checkbox]').bind('click change', function(){

  var getElementType = $(this + ' + input').attr('type');
  console.log(getElementType);


});


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

From the checkbox, you would want to go up to its parent (the label), and then check the next element.

... = $(this).parent().next().attr('type');

Hey paul

THanks for the solution. It works!