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');
精彩评论