unobtrusive-javascript

So what if custom HTML attributes aren't valid XHTML?

半腔热情 提交于 2019-11-26 14:26:14
I know that is the reason some people don't approve of them, but does it really matter? I think that the power that they provide, in interacting with JavaScript and storing and sending information from and to the server, outweighs the validation concern. Am I missing something? What are the ramifications of "invalid" HTML? And wouldn't a custom DTD resolve them anyway? The ramification is that w3c comes along in 2, 5, 10 years and creates an attribute with the same name. Now your page is broken. HTML5 is going to provide a data attribute type for legal custom attributes (like data-myattr="foo"

How to check browser for touchstart support using JS/jQuery?

你说的曾经没有我的故事 提交于 2019-11-26 08:04:47
问题 In an attempt to follow best practices, we\'re trying to use the proper JavaScript/jQuery events according to what device you are using. For example, we\'re building a mobile site that has an tag that will have an onclick or touch event. In the case of an iPhone, we\'d like to use the \"touchstart\" event. We\'d like to test if their device supports \"touchstart\" before we bind that handler to the object. If it doesn\'t, then we will bind \"onclick\" instead. What is the best way to do this?

What is Unobtrusive Javascript in layman terms?

倖福魔咒の 提交于 2019-11-26 06:39:14
问题 What is Unobtrusive Javascript in layman terms? An example would be nice to aid my understanding. 回答1: Checkout the wikipedia article: Unobtrusive JavaScript "Unobtrusive JavaScript" is a general approach to the use of JavaScript in web pages. Though the term is not formally defined, its basic principles are generally understood to include: Separation of functionality (the "behavior layer") from a Web page's structure/content and presentation Best practices to avoid the problems of

Difference between obtrusive and unobtrusive javascript

纵然是瞬间 提交于 2019-11-26 03:56:37
问题 What is the difference between obtrusive and unobtrusive javascript - in plain english. Brevity is appreciated. Short examples are also appreciated. 回答1: I don't endorse this anymore as it was valid in 2011 but perhaps not in 2018 and beyond. Separation of concerns. Your HTML and CSS aren't tied into your JS code. Your JS code isn't inline to some HTML element. Your code doesn't have one big function (or non-function) for everything. You have short, succinct functions. Modular. This happens

window.onload vs $(document).ready()

女生的网名这么多〃 提交于 2019-11-25 22:53:42
问题 What are the differences between JavaScript\'s window.onload and jQuery\'s $(document).ready() method? 回答1: The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded. The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds

Event binding on dynamically created elements?

白昼怎懂夜的黑 提交于 2019-11-25 22:09:32
问题 I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off . This happens on page ready and works just fine. The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won\'t have the event bound. I have found this plugin (jQuery Live Query Plugin), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this,