how to simulate $ function when can't use jquery
my iphone can't use jquery , so i have to simulate 开发者_StackOverflow$ function by myself:
this is my code :
function $(str){
var div=document.createElement('div')
div.innerHTML=str;
return div
}
and you can see , the result has a Redundant parent div,
so how to clear the raw div ,
thanks
I'd think you could instead return div.childNodes[0]
.
What exact behavior(s) of $ are you trying to replicate. It does a lot:
$('#anid') //returns a DOM element reference if found
$('.aClass') //returns either one or more DOM element references
$('<a href="http://a.link.com">A Link</a>') // generates a DOM element and returns it
$(document) //passes a DOM reference into jQuery to be acted on
var a = document.getElementById('anid');
$(a) //passing in a DOM element reference for jQuery to act on.
So as you can see, $() does a lot. What exactly are you trying to achieve? Additionally, is this only for the iPhone or is the project you're working on expected to work on non-webkit browsers too?
Once this function callisover
returndiv=$(str); this.div=returndiv document.body.appendChilde(returndiv)
this should make it work
精彩评论