jQuery what instead $(this).parent().children()

Mr Sooul picture Mr Sooul · May 27, 2011 · Viewed 53k times · Source

Just a quick example:

<p>
    <span class="example"></span>
    <input type="text" name="e_name" id="e_id />
</p>
<script type="text/javascript">
    $('input').click(function(){
        $(this).parent().children('span').text('Suprise!');
    }
</script>

What can I use instead parent().children()?

I think it's a bit inelegant piece of code. Is any function i.e : $(this).fun('span').text('just better'); ??

Answer

Christopher Armstrong picture Christopher Armstrong · May 27, 2011
$(this).siblings('span').text('Suprise!');