开发者

Retrieve 'elementname' from $('elementname')?

Relevent HTML:

<p id="baz"></p>

Relevent code:

function foo(element) {
    element.innerHTML = 'bar';
    alert(element.toString() + ' has been modified');
}

foo($('baz'));

Relevent jsfiddle

This alerts "[object HTMLParagraphElement] has bee开发者_运维知识库n modified". Is there any way to have "baz has been modified"?


Try this, replace element.toString() with .get('id')

function foo(elementname) {
    elementname.set("html", 'bar');
    alert(elementname.get('id') + ' has been modified');
}

foo('baz');


function foo(elementname) {
    $(elementname).innerHTML = 'bar';
    alert(elementname + ' has been modified');
}

foo('baz');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜