Javascript

From LemonWiki共筆
Revision as of 03:12, 16 February 2013 by Planetoid (talk | contribs)
Jump to navigation Jump to search

Javascript approaches to do the same task

get the document by id

  • document.getElementById('abcId')
  • alternative: (1) Get the id attribute by using jQuery attr(): $("selector").attr("id");[1] (example) and (2) go to the first step
  • parallel naming rules for html elemnt tags ex: <input id='checkbox_id1' > & <select id="select_id1">

HTML select form Attribute

display or hide the element by id

  • HTML DOM Style object
    • document.getElementById( selector_id ).style.display = "none";
  • Using jQuery .show() or .hide():
    • $("#selector_id").show(); or
    • $("#selector_id").hide();
  • Using jQuery .css():
    • $("#selector_id").css("display", ""); or $("#selector_id").css("display", "block");
    • $("#selector_id").css("display", "none");

references