And here is a short but revealing example (using jQuery as Javascript library).
The index.html lists 3 languages:
- Ruby
- Python
- Javascript
- Ruby
- Python
- Javascript
After refactoring the index.html to:
- Ruby
- Python
- Javascript
$(document).ready(function(){ $("#languages li").click(function(event){ $(this).toggleClass("selected"); }); });both logic and presentation looks much cleaner.
The refactored example:
- Ruby
- Python
- Javascript
Never pollute your HTML with any Javascript.
Supported by jQuery 1.10.2
Keine Kommentare:
Kommentar veröffentlichen