Home  >  Article  >  WeChat Applet  >  How to get the value of class in dom

How to get the value of class in dom

php中世界最好的语言
php中世界最好的语言Original
2018-06-04 15:51:464598browse

This time I will show you how to get the value of class in the dom, and what are the precautions for getting the class value in the dom. The following is a practical case, let's take a look.

vue clicks to add a class to the dom and then gets the dom containing the class

<p class="chose-ck" v-for="(item,index2) in colors" :key="index2" ref="chosebox">
                  <p>{{item.name}}</p>
                  <dt v-for="(item2,index) in item.childsCurGoods" :key="item2.id" :class="index==iac[index2]?&#39;check&#39;:&#39;&#39;" :id="item2.id" :data-chosename="item.name" :data-choseidname="item2.name" :data-chose="item.id" :data-id="item2.id" @click="chek(index2,index)" >
                    {{item2.name}}
                  </dt>
                </p>js
  chek(index2, index) {
      this.iac[index2] = index
      this.iac = this.iac.concat([]);
      this.checkchose()
    },
    checkchose:function(){
      var chose=this
      var chosedom=chose.$refs.chosebox
      console.log(chosedom)
      for (var i=0;i<chosedom.length;i++) {
        var children=chosedom[i].children
        for (var j=0;j<children.length;j++) {  
          if(children[j].className=="check")
          {
            console.log(children[j])
          }
        }
      }
      
    }

The dom obtained after clicking is printed

if(children[j].className=="check")

Added Determine why the printed DOM is the DOM before clicking

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Make a mobile WeChat public account (with code)

JS chain call (with code) Code)

The above is the detailed content of How to get the value of class in dom. For more information, please follow other related articles on the PHP Chinese website!

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