zoukankan      html  css  js  c++  java
  • jQuery html() example

     

    jQuery html() is used to get the html contents of the first element of the matched elements; While html(‘new html content’) is used to replace or set the html contents of all the matched elements.

    For example, two div elements that contains same class name “AClass”.

    <div class="AClass">ABC 1</div>
    <div class="AClass">ABC 2</div>
    

      

    1. $(‘.AClass’).html()

    This will get the “ABC 1” only, the second matched element “ABC 2″ will be ignore.

     

    2. $(‘.AClass’).html(‘This is new text‘)

    This will replace the html content of all the matched elements.

    <div class="AClass"><b>This is new text</b></div>
    <div class="AClass"><b>This is new text</b></div>
    

      

    jQuery html() example

    <html>
    <head>
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
     
    <style type="text/css">
    	.htmlClass{
    		padding:8px;
    		border:1px solid blue;
    		margin-bottom:8px;
    	}
    </style>
     
    </head>
    <body>
      <h1>jQuery html() example</h1>
     
      <div class="htmlClass">I'm going to replate by something ....</div>
     
      <div class="htmlClass">I'm going to replate by something 2....</div>
     
      <p>
      <button id="getHtml">html()</button>
      <button id="setHtml">html('xxx')</button>
      <button id="reset">reset</button>
      </p>
     
      <script type="text/javascript">
     
        $("#getHtml").click(function () {
     
    	  alert($('.htmlClass').html());
     
        });
     
        $("#setHtml").click(function () {
     
    	  $('.htmlClass').html('<b>This is a new text</b>');
     
        });
     
        $("#reset").click(function () {
    	  location.reload();
        });
     
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    颜色混合openglglBlendFunc函数
    Types of Maps
    ogre 检测显卡gpu支持参数
    (转载)lua和c/c++互相调用实例分析
    光照模型
    阴影(转载)
    eval()解析JSON
    android中The connection to adb is down,问题和解决 AndroidEclipseAntXML
    比较android中的像素单位dp、px、pt、sp
    区别:DOM Core 与 HTMLDOM
  • 原文地址:https://www.cnblogs.com/hephec/p/4574439.html
Copyright © 2011-2022 走看看