如何获取GitHub HTML div元素的gist ID

huangapple go评论112阅读模式
英文:

how to get github html div element gist id

问题

I use GitHub gist to load my sample code to my personal blog. I design a webpage and gist is loaded. each gist create a div element:

<div id="gist*********" class="gist"></div>

also see this image:
github gist div id

I using clipboard.js to copy my gist to the clipboard with the target. the target is an id that begins with gist word. now I want to reach this id but I cannot find any way. any idea?

notice: I am blogger and I need to create many gists in a blog post so I must use a target with clipboard.js

sample codes:

button code:

<button class="btn btn-sm btn-outline-primary copy-to-clipboard font-weight-bold" data-clipboard-target="#gist100405804">copy<i class="fas fa-copy ml-2"></i></button>

init clipboard js:

new ClipboardJS('.copy-to-clipboard');

英文:

I use GitHub gist to load my sample code to my personal blog. I design a webpage and gist is loaded. each gist create a div element:

  1. &lt;div id=&quot;gist*********&quot; class=&quot;gist&quot;&gt;&lt;/div&gt;

also see this image:
github gist div id

I using clipboard.js to copy my gist to the clipboard with the target. the target is an id that begins with gist word. now I want to reach this id but I cannot find any way. any idea?

notice: I am blogger and I need to create many gists in a blog post so I must use a target with clipboard.js

sample codes:

button code:

  1. &lt;button class=&quot;btn btn-sm btn-outline-primary copy-to-clipboard font-weight-bold&quot; data-clipboard-target=&quot;#gist100405804&quot;&gt;copy&lt;i class=&quot;fas fa-copy ml-2&quot;&gt;&lt;/i&gt;&lt;/button&gt;

init clipboard js:

  1. new ClipboardJS(&#39;.copy-to-clipboard&#39;);

答案1

得分: 1

[id^="gist"] 这将选择所有以 gist 值开头的元素。

  1. <!-- begin snippet: js hide: false console: true babel: false -->
  2. <!-- language: lang-js -->
  3. console.log($('[id^="gist"]').text())
  4. <!-- language: lang-css -->
  5. [id^="gist"]{
  6. color:red;
  7. }
  8. <!-- language: lang-html -->
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  10. <div id="gist01654">a</div>
  11. <span id="gist_4">b</span>
  12. <div id="654gist">c</div>
  13. <div id="gis01654">d</div>
  14. <!-- end snippet -->
英文:

[id^=&quot;gist&quot;] this will select all elements starting with gist value

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. console.log($(&#39;[id^=&quot;gist&quot;]&#39;).text())

<!-- language: lang-css -->

  1. [id^=&quot;gist&quot;]{
  2. color:red;
  3. }

<!-- language: lang-html -->

  1. &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  2. &lt;div id=&quot;gist01654&quot;&gt;a&lt;/div&gt;
  3. &lt;span id=&quot;gist_4&quot;&gt;b&lt;/span&gt;
  4. &lt;div id=&quot;654gist&quot;&gt;c&lt;/div&gt;
  5. &lt;div id=&quot;gis01654&quot;&gt;d&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2020年1月6日 17:01:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609208.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定