Home >Web Front-end >JS Tutorial >JS method to implement DIV container assignment_javascript skills

JS method to implement DIV container assignment_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:25:531555browse

The example in this article describes how to implement DIV container assignment using JS. Share it with everyone for your reference, the details are as follows:

Assign a js function to a DIV container, used in ajax, supporting IE and Firefox

<script>
function setValueForDiv(id,content)
{
 var element = document.getElementById(id);
 element.innerHTML = unescape(content);
 if(!element.innerHTML)
 {
  try{
   element.innerHTML = unescape(content);
  }catch(e){}
 }
}
</script>

where id is the id of the div
content: for content

Call example:

<div id="title"> </div>
setValueForDiv(id,content)
<script>
 setValueForDiv("title","this is a test");
</script>

I hope this article will be helpful to everyone in JavaScript programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn