Search code examples
javascriptjqueryparentchildren

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


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'); ??


Solution

  • $(this).siblings('span').text('Suprise!');