开发者

My javascript to jQuery translation has a bug

开发者 https://www.devze.com 2022-12-25 07:14 出处:网络
My guess is that this javascript just finds the div called divid and then uses it with the sendit function.

My guess is that this javascript just finds the div called divid and then uses it with the sendit function.

var somevalue = 19; 
if (navigator.appName.indexOf("Microsoft") != -1) {
    thediv = window["divid"]; 
} else { 
    thediv = document["divid"];
}
thediv.sendit(somevalue);

I would imagine in jQuery it would look something as simple as this:

var somevalue = 19;
$('divid').sendit(somevalue);

But it's not 开发者_运维百科working!! What could I be missing?

I should say that it's in the middle of other javascript code, could that be a problem?


You would need to get the actual DOM object (not the JQuery collection) to access the function that you set on it.

$('divid').get(0).sendit(somevalue);


Assuming there is an element with ID 'divid' you need to use the ID selector #

var somevalue = 19;
$('#divid').sendit(somevalue);

That may not be the whole answer as it's unclear where sendit is defined.

0

精彩评论

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