Reputation: 68750
I have a Div which may contain an INPUT with a class of "datepicker"
<div class="rereg-input180">
... some layers
<input class="one two datepicker three">
....
I need to apply a Style="clear" to the top div. However I don't want to if that div doesn't contain a datepicker child.
How do I select it?
Upvotes: 0
Views: 85
Reputation: 1258
You could use: jQuery's .parent()
$(".datepicker").parent().css("clear","both");
Upvotes: 0
Reputation: 16438
You can use .has() http://api.jquery.com/has/ assuming you want the clear both, if it's a clear class, the you can just .addClass() instead of .css()
$('.rereg-input180').has('.datepicker').css('clear', 'both');
if you want to be more specific you can do
$('.rereg-input180').has('input.datepicker').css('clear', 'both');
Upvotes: 1
Reputation: 680
You could also do:
$('.datepicker').closest('.rereg-input180').addClass('clear');
Upvotes: 2
Reputation: 341
You can use this selector:
$('div.rereg-input180:has(:text.datepicker)').css('clear', 'both')
Upvotes: 1
Reputation: 44740
You can do this -
$div = $('.rereg-input180');
if($div.find('.datepicker').length){
// apply style
}
Upvotes: 2