开发者

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

开发者 https://www.devze.com 2023-03-15 18:29 出处:网络
Relevent HTML: <p id=\"baz\"></p> Relevent code: function foo(element) { element.innerHTML = \'bar\';

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

精彩评论

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