изменить размер шрифта для getElementsByClassName

я отбрасываю абзац на странице с помощью getElementsByClassName. Однако я не могу изменить размер и цвет шрифта выходной.

ниже мой код для лома.

var keyPeople1 = tmp.body.getElementsByClassName("cr_profile_people module")[0].children;
for (var i = 0; i < keyPeople1.length; i++) {
  keyPeople1[i].style.fontSize = "2em";
}
$scope.keyPeople = "<div class='cr_profile_people module'><div class='mod_headerBox'>"+keyPeople1[0].innerHTML+"</div><div class='cr_data cr_board'>"+keyPeople1[1].innerHTML+"</div></div>";

цикл for должен был изменить размер шрифта, но он просто не работает.

фрагмент html

<div style="margin: 10px;" ng-bind-html="keyPeople"></div>

добавить fontsize в стиле <div style="margin: 10px;font-size:60%;"ng-bind-html="keyPeople"></div> не влияет на размер шрифта.

пожалуйста, помогите правильно изменить размер шрифта и его цвет. enter image description here

код

угловой js для лома страницы

.controller("companyOwnershipCtrl",function($scope,$http,$ionicLoading,$state,$cashDataFactory){


  $ionicLoading.show();

  $http.get("http://vinn.johnapi.com/wsjapi?url=http://quotes.wsj.com/SG/U11/company-people")
  .success(function(response){
    $ionicLoading.hide();
    var tmp = document.implementation.createHTMLDocument();

    tmp.body.innerHTML = response;

    //Company Info
    var companyInfo1 = tmp.body.getElementsByClassName("cr_profile_contact")[0].children;
    var companyInfo2 = tmp.body.getElementsByClassName("cr_overview_data cr_data")[0].children;

    $scope.companyInfo = "<div class='cr_profile_contact'>"+companyInfo1[0].innerHTML+"</div>";
    $scope.companyInfo += "<div class='cr_overview_data cr_data'>"+companyInfo2[0].innerHTML+"</div>";

    //Description
    var description1 = tmp.body.getElementsByClassName("cr_description_full cr_expand")[0].children;
    $scope.companyDescription = "<p>"+description1[0].innerHTML+"</p>";

    //Key People
    var keyPeople1 = tmp.body.getElementsByClassName("cr_profile_people module")[0].children;
    $scope.keyPeople = "<div class='cr_profile_people module'><div class='mod_headerBox'>"+keyPeople1[0].innerHTML+"</div><div class='cr_data cr_board'>"+keyPeople1[1].innerHTML+"</div></div>";

    //Average Growth Rates
    var growth = tmp.body.getElementsByClassName("cr_profile_growth module")[0].children;
    var growth1 = tmp.body.getElementsByClassName("cr_profile_insider module")[0].children;
    $scope.averageGrowthRates = "<div class='cr_profile_growth module'><div class='mod_headerBox'>"+growth[0].innerHTML+"</div><div class='cr_data'>"+growth[1].innerHTML+"</div></div>";
    $scope.averageGrowthRates += "<div class='cr_profile_insider module'><div class='mod_headerBox'>"+growth1[0].innerHTML+"</div><div class='cr_data'>"+growth1[1].innerHTML+"</div><div class='cr_data'>"+growth1[2].innerHTML+"</div></div>";

    //ownership
    var ownership = tmp.body.getElementsByClassName("cr_profile_ownership module")[0].children;
    $scope.averageGrowthRates += "<div class='cr_profile_ownership module'><div class='mod_headerBox'>"+ownership[0].innerHTML+"</div><div class='cr_data'>"+ownership[1].innerHTML+"</div><div class='cr_data'>"+ownership[2].innerHTML+"</div></div>";
  }).error(function(error){

    $ionicLoading.hide();
    console.log(error.data);

  });

HTML-код

<ion-view view-title="Company">
  <ion-nav-buttons side="left">
  </ion-nav-buttons>
<ion-content id="comp">
  <ion-scroll>
    <h3 style="margin: 10px;">Company Info</h3>
    <div style="margin: 10px;" ng-bind-html="companyInfo"></div>
    <h3 style="margin: 10px;">Description</h3>
    <div style="margin: 10px;font-size:20px;" ng-bind-html="companyDescription"></div>
    <div style="margin: 10px;color:#AAAFFF;font-size:40px;" ng-bind-html="keyPeople"></div>s   
    <div style="margin: 10px;" ng-bind-html="averageGrowthRates"></div>
    <div style="margin: 10px;" ng-bind-html="ownership"></div>
  </ion-scroll>
</ion-content>
</ion-view>

обновление: С текущими ответами @Manzurul и @Varun Sukheja.

  1. размер шрифта и цвет внутри красного поля Я рисую, оба не вступают в силу

  2. размер шрифта таблицы под красным полем не вступает в силу, только цвет измененный.

таким образом, мне любопытно, почему размер шрифта внутри красного поля не может измениться? Важнее, как его изменить.

изображение использует

.controller("companyOwnershipCtrl",function($scope,$http,$ionicLoading,$state,$cashDataFactory){

$scope.companyDescriptionStyle = {"color": "blue", "font-size": "40px"}; 

в angularjs и <div style="margin: 10px;font-size:20px;" ng-bind-html="companyDescription" ng-style="companyDescriptionStyle"></div> в html, но вы можете заметить, что размер шрифта такой же, как и выше.

enter image description here

html код, который слом из этой ссылки http://quotes.wsj.com/SG/U11/company-people

<div class="cr_profile_people module"> <div class="mod_headerBox"> <h3>Key People <span class="hdr_co_name">United Overseas Bank Ltd.</span></h3> </div> <div class="cr_data cr_board"> <h4>Board of Directors</h4> <table class="cr_dataTable cr_board_table"> <tbody> <tr> <th>Name/Title</th> <th>Current Board Membership</th> </tr> </tbody> </table> <div class="scrollBox"> <table class="cr_dataTable cr_board_table"> <tbody> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86291589">Ee Cheong Wee</a>, <span class="data_meta">63</span> </span> <span class="data_lbl">Deputy Chairman &amp; Chief Executive Officer</span> </td> <td> <span class="data_lbl">PT Bank UOB Indonesia, Visa International Senior Client Council, United Overseas Bank Ltd., Singapore-China Foundation Ltd., Far Eastern Bank Ltd., United Overseas Insurance Ltd., United Overseas Bank (Thai) Public Co. Ltd., United Overseas Bank (Malaysia) Bhd., The Institute of Banking &amp; Finance, United Overseas Bank (China) Ltd., Wee Foundation, United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/16055509">Michael Lien</a>, <span class="data_meta"></span> </span> <span class="data_lbl">Non-Executive Director</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/104206">Cho Yaw Wee</a>, <span class="data_meta">88</span> </span> <span class="data_lbl">Chairman-Emeritus</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/16489539">Fu Hua Hsieh</a>, <span class="data_meta">66</span> </span> <span class="data_lbl">Chairman</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86320739">Khirn Hai Yeo</a>, <span class="data_meta">55</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/154674047">Kan Seng Wong</a>, <span class="data_meta">71</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/13470908">Alexander Charles Hungate</a>, <span class="data_meta">51</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/98308786">Hwee Hua Lim</a>, <span class="data_meta">57</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore), BW Group Ltd., Jardine Cycle &amp; Carriage Ltd., Stewardship &amp; Corporate Governance Centre Pte Ltd., PAP Community Foundation, Stewardship Asia Centre Pte Ltd.</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/104667">Cher Siang Koh</a>, <span class="data_meta">70</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">Singapore Housing &amp; Development Board, United Overseas Bank Ltd., CapitaLand Ltd., United Overseas Bank Ltd. (Singapore), Thye Hua Kwan Moral Charities Ltd., Mechanobiology Institute, Singapore Golf Association, Singapore Cooperation Enterprise, CapitaLand Hope Foundation, Singapore Deposit Insurance Corp., Singapore Island Country Club</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/114522422">Yew Huat Ong</a>, <span class="data_meta">60</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">United Overseas Bank Ltd. (Singapore)</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86318967">Jue Hiang Cheng</a>, <span class="data_meta">62</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">SPH MediaBoxOffice Pte Ltd., SPH Interactive Pte Ltd., FEO Hospitality Trust Management Pte Ltd., Far East Hospitality Trust, FEO Hospitality Asset Management Pte Ltd., SPH Interactive International Pte Ltd., Singapore Institute of Directors, 701Search Pte Ltd., Ntuc Fairprice Foundation Ltd., Ashoka Innovators for the Public (Singapore) Ltd., United Overseas Bank Ltd. (Singapore), Council For Third Age Ltd., Integrated Information Systems, Inc., Aescapulus Holdings Pte Ltd., Singapore Health Services Pte Ltd., Integrated Health Information Systems Pte Ltd., SymAsia Foundation Ltd., Asia Philantrophic Ventures Pte Ltd., Asia Philanthropic Ventures Pte Ltd., Caritas Humanitarian Aid &amp; Relief Initiatives, Singapore</span> </td> </tr> <tr> <td> <span class="data_data"> <a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/41491049">Franklin Leo Lavin</a>, <span class="data_meta">58</span> </span> <span class="data_lbl">Independent Non-Executive Director</span> </td> <td> <span class="data_lbl">Far Eastern Bank Ltd., Globe Specialty Metals, Inc., CONSISTEL (Singapore) Pte Ltd., United Overseas Bank Ltd. (Singapore), United Overseas Bank Ltd., Export Now, Inc.</span> </td> </tr> </tbody> </table> </div> <div class="bottomStrap_more"> <a href="#" id class="moreLink loadMoreLink">expand</a> </div> </div> <div class="cr_data cr_all_executives"> <h4>All Executives</h4> <div class="scrollBox"> <ul class="cr_data_collection cr_all_executives"> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86291589">Ee Cheong Wee</a></span> <span class="data_lbl">Deputy Chairman &amp; Chief Executive Officer</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86291593">Wai Cheng Hwee</a></span> <span class="data_lbl">Head-Group Technology &amp; Operations</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86291587">Wai Fai Lee</a></span> <span class="data_lbl">Chief Financial Officer</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/4815192">Victor Ngo</a></span> <span class="data_lbl">Head-Group Compliance</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/122181365">See-Ming Ip Yeung</a></span> <span class="data_lbl">Managing Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/122099381">Chin Voon-Fat</a></span> <span class="data_lbl">Head-Group Wholesale Banking</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/120136914">Kok Seong Chan</a></span> <span class="data_lbl">Group Chief Risk Officer</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/115461061">Wah Yan Wong</a></span> <span class="data_lbl">Head-Group Strategy &amp; International Management</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/160726">Terence Ong</a></span> <span class="data_lbl">Head-Global Markets &amp; Investment Management</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86328526">Chin Yong Lee</a></span> <span class="data_lbl">Head-Group Retail</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/16055509">Michael Lien</a></span> <span class="data_lbl">Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/104206">Cho Yaw Wee</a></span> <span class="data_lbl">Chairman-Emeritus</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/152463410">Carrie Ann Mathews</a></span> <span class="data_lbl">Head-Group Strategic Communications</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/120300850">Shih Tung Lin</a></span> <span class="data_lbl">Investor Relations Contact</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/95901534">Mei Leng Wong</a></span> <span class="data_lbl">Head-Group Human Resources</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/138452461">Ming Kuang Sia</a></span> <span class="data_lbl">Co-Secretary</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/151489730">Kwee Soik Sim</a></span> <span class="data_lbl">Co-Secretary</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/16489539">Fu Hua Hsieh</a></span> <span class="data_lbl">Chairman</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86320739">Khirn Hai Yeo</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/154674047">Kan Seng Wong</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/13470908">Alexander Charles Hungate</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/98308786">Hwee Hua Lim</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/104667">Cher Siang Koh</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/114522422">Yew Huat Ong</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/86318967">Jue Hiang Cheng</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> <li> <div class="cr_data_field"> <span class="data_data"><a href="http://quotes.wsj.com/SG/XSES/U11/company-people/executive-profile/41491049">Franklin Leo Lavin</a></span> <span class="data_lbl">Independent Non-Executive Director</span> </div> </li> </ul> </div> <div class="bottomStrap_more"> <a href="#" id class="moreLink loadMoreLink">expand</a> </div> </div> </div> </div> <!--data-module-name="quotes.module.companypeople.Module"--> <div intent in-at8units-append="#at8uTarget" in-at12units-append="#at12uTarget" in-at16units-append="#at12uTarget"> <div data-module-id="12" data-module-name="quotes.module.ads.responsiveAd" data-module-zone="ads" class="zonedModule"> <div class="boxadWrapper module" id="main-quotes-ad"> <span class="adTitle">Advertisement</span> <div class="quotes-ad-wrap" id="AD_G" data-ad-options="{&quot;adId&quot;:&quot;AD_G&quot;,&quot;adUnitPath&quot;:&quot;/2/asia.wsj.com/quotes_front&quot;,&quot;adSize&quot;:[[300,250],[300,1050]],&quot;adSizeMap&quot;:null,&quot;autoRefresh&quot;:false,&quot;adTargeting&quot;:{&quot;metazone&quot;:&quot;&quot;,&quot;msrc&quot;:null,&quot;circ&quot;:&quot;nonsub&quot;,&quot;sym&quot;:&quot;U11&quot;,&quot;p39&quot;:null}}" data-tracking="asia.wsj.com/quotes_front" data-cb-ad-id="TopRectangle"> </div> </div> </div>

3 ответов


Как насчет CSS только решение вашей проблемы

.cr_profile_people.module > .mod_headerBox > h3 {
    font-size: 10px!important;
}

.cr_profile_people.module .cr_dataTable.cr_board_table > tbody > tr > th {
    font-size: 40px!important;
}

посмотрите, я использовал ваш весь ионный html-код, а также сохранил теги h3. И NG-style работает нормально.

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $http) {

  /*$http.get("http://manzurul.atwebpages.com")
  .success(function(response){ 
    console.log('workingsdfsdf');
    
  }).error(function(error){
 
    if(!error) {
        $scope.name = "No data found"
        $scope.companyDescriptionStyle = {"color": "red","font-size":"40px"}
    }
  });*/
  $scope.companyDescriptionStyle = {
    "color": "blue",
    "font-size": "40px"
  };
  $scope.name = 'World';
  //Company Info
  var companyInfo1 = null;
  var companyInfo2 = null;

  $scope.companyInfo = null;
  $scope.companyInfo += "";

  //Description
  var description1 = "";
  $scope.companyDescription = "<p></p>";


  //Key People
  var keyPeople1 = "";
  $scope.keyPeople = "";

  //Average Growth Rates
  var growth = "";
  var growth1 = "";
  $scope.averageGrowthRates = "";
  $scope.averageGrowthRates += "";

  //ownership
  var ownership = "";
  $scope.averageGrowthRates += "";
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<div ng-app="plunker">
  <div ng-controller="MainCtrl">
    <p ng-style="nameStyle">Hello {{name}}!</p>
    <ion-view view-title="Company">
      <ion-nav-buttons side="left">
      </ion-nav-buttons>
      <ion-content id="comp">
        <ion-scroll>
          <h3 ng-style="companyDescriptionStyle">Company Info</h3>
          <div style="margin: 10px;" ng-bind-html="companyInfo"></div>
          <h3 ng-style="companyDescriptionStyle">Description</h3>
          <div style="margin: 10px;font-size:20px;" ng-bind-html="companyDescription"></div>
          <div style="margin: 10px;color:#AAAFFF;font-size:40px;" ng-bind-html="keyPeople"></div>
          <div style="margin: 10px;" ng-bind-html="averageGrowthRates"></div>
          <div style="margin: 10px;" ng-bind-html="ownership"></div>
        </ion-scroll>
      </ion-content>
    </ion-view>
  </div>
</div>

вы можете использовать ng-class direcitve для применения вашего класса

см. использование здесь:ng-class Вы можете определить класс в файле css

    . companyDescriptionStyle {"color":"blue"};

нет вы можете использовать этот класс в ng-class

    <div style="margin: 10px;font-size:20px;" ng-bind-html="companyDescription" ng-class="companyDescriptionStyle"></div>