如何使用jQuery选择具有自定义类名的元素

时间:2017-12-23 19:25:15

标签: javascript jquery

我想用jQuery选择一个textarea元素,其类名为sendMessage

<script>tinymce.init({ selector:'textarea' });</script>

那么如何将这个特定元素的classname添加到这行代码中呢?

2 个答案:

答案 0 :(得分:2)

类选择器由点(。)表示,如下所示

debian:~/user$ curl -Ss -H "Authorization: Bearer atkn" https://api.spotify.com/v1/users/bugenwilla/playlists|jq -r '.items[]|select(.name=="myplaylist")|[.tracks.total, .id]'
[
  1543,
  "playlistid"
]

debian:~/user$ curl -Ss -H "Authorization: Bearer atkn" https://api.spotify.com/v1/users/username/playlists/playlistid/tracks | jq -r '.items[] | .track.album.artists[].name' | wc -l
108

debian:~/user$ curl -Ss -H "Authorization: Bearer atkn" https://api.spotify.com/v1/users/username/playlists/playlistid/tracks | jq -r '.limit, .total'
100
1543

答案 1 :(得分:0)

<强> Working fiddle

你可以简单地使用类符号(点).,它看起来像:

tinymce.init({ selector:'.sendMessage ' });
//or
tinymce.init({ selector:'textarea.sendMessage ' });

段:

&#13;
&#13;
tinymce.init({
  selector: "textarea.sendMessage"
});
&#13;
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="sendMessage">Congratulations!</textarea>
&#13;
&#13;
&#13;