JQuery
设置/取消 css class, addClass / removeClass
- addClass
- https://api.jquery.com/addClass/
.addClass( className )
.addClass( function )
- removeClass
- https://api.jquery.com/removeClass/
.removeClass( [className ] )
.removeClass( function )
1 2 3 4 5 6 7 8 9 10 11 | $( "p" ).addClass( "myClass yourClass" ); $( "p" ).removeClass( "myClass yourClass" ) $( "p" ).removeClass( "myClass noClass" ).addClass( "yourClass" ); $( "li:last" ).removeClass(function() { return $( this ).prev().attr( "class" ); }); |
删除标签内的文字
- REFER TO : https://stackoverflow.com/a/1571097/3316529
1 2 3 4 5 | $(elem) .contents() .filter(function() { return this.nodeType == 3; //Node.TEXT_NODE }).remove(); |