JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 8th, 2013, 05:29 PM
karwork karwork is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 karwork User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 4 sec
Reputation Power: 0
Wink Other - Create a JavaScript selection

Hi everyone!,
I'm learning javascript, that is why need your help.
I have this template
<javascript>
var $ = function (selector) {
var elements = [];

return elements;
}
</javascript>
in elements i have to return array that contenst the selector with the value, and when call $("div") - Should return 2 DIVs
any idea how to do it? thanks to all in advance.

Reply With Quote
  #2  
Old February 8th, 2013, 08:44 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,046 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 4 h 54 m 33 sec
Reputation Power: 812
Hi,

there is no "javascript" element in HTML. I guess you meant
Code:
<script type="text/javascript"></script>


Also, what exactly is the point of your script? Reinventing jQuery?

Reply With Quote
  #3  
Old February 9th, 2013, 11:37 AM
karwork karwork is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 karwork User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 4 sec
Reputation Power: 0
Hi, I think I didn't explain very well.
I have 3 files
Test.html contains the HTML function will be tested
<!DOCTYPE html>
<head>
<script src="Answer.js"></script>
<script src="Test.js"></script>
</head>
<body>
<div></div>
<div id="some_id" class="some_class some_other_class"></div>
<img id="some_other_id" class="some_class some_other_class"></img>
<input type="text">
</body>
Test.js contains a function which provide results for your answer in the developer console
Answer.js contains a template function that should return an array of DOM elements that match the CSS selector.

var $ = function (selector) {
var elements = [];

return elements;
}
I hope I give more idea, what I want to do. thanks!

Reply With Quote
  #4  
Old February 9th, 2013, 03:55 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,046 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 4 h 54 m 33 sec
Reputation Power: 812
I understand what you're trying to do. The question is why you want to do it, because you're reinventing the wheel. Every framework on this planet (jQuery, Prototype, YUI, ...) has those element selectors already. So unless you do this purely for learning, it's pretty pointless.

Anyway, selecting all elements of the same type is a native JavaScript method:
getElementsByTagName

Reply With Quote
  #5  
Old February 9th, 2013, 04:15 PM
karwork karwork is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 karwork User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 4 sec
Reputation Power: 0
yes, you right. But I'm learning that is why. Anyway thanks for try to understand me

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Other - Create a JavaScript selection

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap