1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryでHTMLのツリーを編集する

Last updated at Posted at 2019-10-21

結局使わなかったコードをお焚き上げ。
<link>タグの追加と指定したタグ削除をjQueryで行うコードです。
リストが6件以下だったらタグ消してCSS1読み込んで、違ったらCSS2読み込む、といった流れです。

<script type="text/javascript">
	$(function() {
	if (6 >= $('#foo_list').children().length ) {
		// リストが6件以下

		// CSS1を読込む
		$('head').append('<link rel="stylesheet" href="css/style_1.css" media="all" />');

		// タグの削除
		$('#bar_list').remove();
		$('#hoge_list > label').remove();
	} else {
		// リストが6件以上

		// CSS2を読込む
		$('head').append('<link rel="stylesheet" href="css/style_2.css" media="all" />');
	}
	});
</script>
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?