JavaScript +通过ID&查找对象类路径 [英] JavaScript + find an object by ID & Class Path
问题描述
我使用JQUERY,但在特定情况下需要使用一段JavaScript.我遇到的问题是能够在Javascript中引用我想要的特定对象.
I use JQUERY but have the need to use a piece of JavaScript in the specific case. The problem I'm having is being able to reference the specific object I want in Javascript.
在JQUERY中,我要声明$('div#uniqueID div.genericClass')
-仅供参考,有很多uniqueID div,并且每个都有以下的genericClass.
In JQUERY I would state $('div#uniqueID div.genericClass')
- FYI there are many of the uniqueID divs and each has the genericClass below.
这是我要使用的Javascript(虽然有更多代码,但在这种情况下并不是特别重要:
This the Javascript I'm trying to use (there is more code but its not specifically important in this case:
function insertEmoticonAtTextareaCursor(uniqueID,text) {
var txtarea = document.getElementById(uniqueID);
}
我正在使用以下命令从JQUERY调用此代码:
I'm calling this code from JQUERY using:
insertEmoticonAtTextareaCursor(uniqueID,emoticonSymbol)
我需要访问的对象是
$('div#uniqueID div.genericClass')
我怎样才能将'txtarea'变量链接到$('div#uniqueID div.genericClass')
?
How can I get the 'txtarea' variable to be linked to $('div#uniqueID div.genericClass')
?
谢谢
推荐答案
尝试一下:
function insertEmoticonAtTextareaCursor(uniqueID,text) {
var txtarea = $("#"+uniqueID).find('div.genericClass');
}
这篇关于JavaScript +通过ID&查找对象类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!