0

How can add class .jokjok in the div next of input[bdate]?

Example: http://jsfiddle.net/cLNJE/1/

This code did not work for me:

<button>Click Me</button>
<div class="pa_row mediumCell">
    <div class="column">
        <input type="text" name="expass">
    </div>
    <div class="column">
        <div class="auto_box2">
            <input type="text" name="bdate">
            <div></div>
        </div>
    </div>
    <div class="column">
        <input type="text" name="old">
    </div>
</div>



$('button').live("click", function () {
    $('input[bdate]').closest('.pa_row ').find('auto_box2 div').removeClass().addClass('jokjok');
    //alert('click is ok')
});
1

4 Answers 4

0

I think you need to specify which attribute you want to use for selection of the right input:

$('input[name="bdate"]');

This worked for me:

$('button').live("click", function () {
    $('input[name="bdate"]').closest('.pa_row').find('div.column div.auto_box2 div').first().removeClass().addClass('jokjok');
});

See: http://jsfiddle.net/cLNJE/7/

Sign up to request clarification or add additional context in comments.

Comments

0

the easy ways is: Add id attribut to div

<div id="someid"></div>
$('button').live("click", function () {
    $('#someid').addClass('jokjok');
});

Or

Create new whole div

$('button').live("click", function () {
        $('input[name="bdate"]').after('<div class="jokjok"></div>');
    });

Comments

0

Some of your selectors are not quite right,

$('input[bdate]')

should be

$('input[name=bdate]')

this will select the input with a name attribute of 'bdate' your previous selector was selecting all inputs that had an attribute of 'bdate'

find('auto_box2 div')

should be

find('div.auto_box2')

this will select the 'div' with a class of 'auto_box2'

Making those changes leaves us with this code -

$('button').live("click", function() {
    $('input[name=bdate]').closest('.pa_row ').find('div.auto_box2').removeClass().addClass('jokjok');
    alert('click is ok')
});

which should hopefully do what you want.

Updated fiddle - http://jsfiddle.net/ipr101/542ZW/1/

Comments

0

http://jsfiddle.net/cLNJE/8/

$('button').live("click", function () {
    $('.auto_box2 input').siblings('div').addClass('jokjok');
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.