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

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

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:

&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:

&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:

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

答案1

得分: 1

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

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

<!-- language: lang-js -->
console.log($('[id^="gist"]').text())

<!-- language: lang-css -->
[id^="gist"]{
  color:red;
}

<!-- language: lang-html -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="gist01654">a</div>
<span id="gist_4">b</span>
<div id="654gist">c</div>
<div id="gis01654">d</div>

<!-- 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 -->

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

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

[id^=&quot;gist&quot;]{
  color:red;
}

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

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;gist01654&quot;&gt;a&lt;/div&gt;
&lt;span id=&quot;gist_4&quot;&gt;b&lt;/span&gt;
&lt;div id=&quot;654gist&quot;&gt;c&lt;/div&gt;
&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:

确定