Home > front end >  How to obtain the jquery div inside so the words and content
How to obtain the jquery div inside so the words and content

Time:09-21

For example,

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>



How to let his alert tip:
Words
XXX. PNG
Words
Words
XXX. PNG
XXX. PNG
Words
Words
XXX. PNG
Words

CodePudding user response:


<body>

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>

Text & lt;/p>



<script type="text/javascript">
Var boxId=document. GetElementById (" box ");
Var iLen=boxId. Children. Length;
Var STR="";
Var strTmp="";
Var strImg="";
for(var i=0; I{
Var tag=boxId. Children [I] tagName.
If (tag=="P")
{
StrTmp +=(boxId. Children [I] textContent + "\ r \ n");

}
Else if (tag=="IMG")
{
StrTmp +=(boxId. Children [I] attributes. [0] value + "\ r \ n");
}
}
Alert (strTmp);
</script>



CodePudding user response:

$(" div "). The text () is the test, is the plain text, div will automatically ignore HTML tags,

$(" div "). The HTML () get the & lt; P> Test

, it is all the content div, including HTML tags, it has a benefit is that will receive the labels and text directly reuse, such as operation added to the page elsewhere,
  • Related