如何在JavaScript中修改父ID的DIV内容?

时间:2015-09-02 23:09:44

标签: javascript dom

如何通过单击上层来设置底层可见?

<div class="inactive">
    <div> <a href="#" onclick="do visible another parent layer"><img src='images/message.png'></a>

    </div>
    <div style="display:none">!Message need to show!</div>
</div>

JS

$jq = jQuery.noConflict(true);
$jq(document).ready(function () {
    $jq('.title').append('<span></span>');
    $jq('.post span').each(function () {
        var trigger = $jq(this),
            state = false,
            el = trigger.parent().next('.entry');
        trigger.click(function () {
            state = !state;
            el.slideToggle();
            trigger.parent().parent().toggleClass('inactive');
        });
    });
});

1 个答案:

答案 0 :(得分:2)

首先遍历DOM以获取$('#myform').validate({ rules: { yourfield: { remote: { url: '/ajax/validator/', type: 'POST', async: false, // data: {field: value}, // not needed, field data is sent by default // dataType: 'json', // not needed, already default // success: {} // not needed, plugin handles response automatically } } }, messages: { yourfield: { remote: 'Invalid national id' } } }); 容器,然后向下移动到下一个兄弟(div)然后显示它。

div

jsfiddle