JavaScript的HTML内容或文字的div [英] javascript get html or text from div
问题描述
这是容易的jQuery但如何对普通的JavaScript?
This is easy in jquery but how about plain javascript?
在code是谷歌图片搜索API。我想搜索匹配一个DIV中的HTML或preferably文本的图像。
The code is for the Google image search API. I want to search images that match the html or preferably text inside a div.
var searchThis = document.getElementById('imgToFind'); //get HTML, or text from div
// Find images
imageSearch.execute(searchThis); //search image
在HTML
<div id="imgToFind">PlayStation</div>
结果应该是游戏机的图像。相反,我得到这些
The result should be images of playstation. Instead I get these
dosic OIS - 123
dosic ois - 123
IE8的JavaScript返回[对象HTMLDivElement]而不是[
IE8 javascript returns [object HTMLDivElement] instead [
爱心手
Loving Hand
和其他无关的图像。我不知道谷歌搜索..觉得第二个是给我一个提示。
And other irrelevant images. I wonder what Google searches for.. think the second one is giving me a hint.
推荐答案
及其 VAR searchThis =的document.getElementById('imgToFind')的innerHTML;
提取唯一可以做的文本:
to extract only text you can do:
element = document.getElementById('imgToFind');
var searchThis = element.textContent || element.innerText;
这篇关于JavaScript的HTML内容或文字的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!