Apps Script公式リファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2019年1月4日金曜日

HTML要素の属性を削除する(removeAttribute)


aタグからhrefを削除する例を書きます



Google検索を開く

上記のリンク部分は以下のように書いています
<a href="https://www.google.com/" id="link" target="_blank">
Google検索を開く
</a>

「リンクを切る」ボタンをクリックするとhrefが削除されます



コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
<body>
  <a id="link" target="_blank" href="https://www.google.com/">Google検索を開く</a>
  <button id="bt">リンクを切る</button>
<script>
var bt = document.getElementById('bt');
bt.onclick = removeHref;

function removeHref() {
  var link = document.getElementById('link');
  link.removeAttribute("href");
}
</script>
</body>
</html>
意訳
 


リンク
ボタン

ボタンを取得する
ボタンをクリックしたらremoveHrefを実行する

この機能がやること
リンクの要素を取得する
リンクのhrefを削除する






Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues https://issuetracker.google.com/savedsearches/566234 Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...