Home > Web Front-end > JS Tutorial > body text

JS method to implement DIV container assignment_javascript skills

WBOY
Release: 2016-05-16 15:25:53
Original
1514 people have browsed it

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>

Copy after login

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>

Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!