Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
8
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@_shimizu

ブラウザ間のメソッドやプロパティの違いを三項演算子を使って吸収する

leafletのサンプルコードを読んでて知った方法。

ブラウザによってinnerTextだったりtextContentだったりを使い分けないといけない時に三項演算子を使ってプロパティやメソッドの違いを吸収する

var textarea = document.querySelector("textarea");
textarea["innerText" in textarea ? "innerText" : "textContent" ] = "text";

input要素のoninputとonchangeの違いなんかもこれで行けるらしい。

var input = document.querySelector("input");
input['oninput' in input ? 'oninput' : 'onchange'] = function(){
    console.log(this.value);
};
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
8
Help us understand the problem. What are the problem?