diff --git a/js/tinyDOM.js b/js/tinyDOM.js index e629bef7f2adca179bd9e11fc70868b523fc6ec4..a87ff40e57029b0308c006bd51187eebf5e00a99 100644 --- a/js/tinyDOM.js +++ b/js/tinyDOM.js @@ -5,17 +5,24 @@ } var tinyDOMFunction = function(selector) { - var elements = document.querySelectorAll(selector); + if(selector === null || typeof(selector) === 'undefined'){ + this.length = 0; + } else if(typeof(selector) === 'string'){ + var elements = document.querySelectorAll(selector); - this.length = elements.length; - for(var i = 0; i < elements.length; i++){ - var e = elements.item(i); - if(typeof(e.td_prop) === 'undefined'){ - e.td_prop = { - isHidden: false - }; + this.length = elements.length; + for(var i = 0; i < elements.length; i++){ + var e = elements.item(i); + if(typeof(e.td_prop) === 'undefined'){ + e.td_prop = { + isHidden: false + }; + } + this[i] = elements.item(i); } - this[i] = elements.item(i); + } else { + this[0] = selector; + this.length = 1; } return this; diff --git a/test.html b/test.html index dccc04d1a46c0cb5297d99dd90cc0fa1870e6db0..4f9a54c721b419c768fff7d89ca1d5ba4ff55d3e 100644 --- a/test.html +++ b/test.html @@ -8,14 +8,19 @@ <body> <h1> this is a title </h1> <div id="test"> + <p> These are <span class="important">words</span>! They are kind of important words too, so it would be <span class='important'>bad</span> if any of them dissapeared. + </p> + <p id='emptydiv'> + + </p> </div> <button id="btn-hide">HIDE THINGS</button> <button id="btn-show">SHOW THINGS</button> - <section class='information' data-href='/info/test.php'> + <section class='information' data-href='tests/get.html'> <h2>About tinyDOM functions</h2> <p> tinyDOM operates on dom elements to make it a bit easier @@ -52,5 +57,17 @@ μ('h1').on('click', function(){ console.log(this); }); + + μ('.information').on('click', function(){ + var url = μ(this).data('href'); + console.log(μ(this).data('href')); + μ.ajax({ + url: url, + success: function(data){ + console.log(data); + μ('#emptydiv').first().innerHTML = data; + } + }); + }); </script> </html> diff --git a/tests/get.html b/tests/get.html new file mode 100644 index 0000000000000000000000000000000000000000..67f22f21c77b9ebfb952c27a3fba5e924b20a998 --- /dev/null +++ b/tests/get.html @@ -0,0 +1,7 @@ +<div> + <p> + This is a piece of text retrieved via some sort of external request. + It is, after all, just a fragment of html and would be a terrible + page in and of itself. + </p> +</div> \ No newline at end of file