[ 7 posts ]

Egor Ushakov

  • Username: erop
  • Joined: Tue Jul 12, 2011 7:51 am
  • Posts: 2
  • Offline
  • Profile

How to get Node by element's name

Post Posted: Fri Mar 23, 2012 2:16 am
+0-
I have a select element which has only the name (neither id, nor CSS, etc.)
Code:
<select name="assigned_user_id_advanced[]" size="6" style="width: 150px" multiple="true">[option_list]</select>

How can I grab it into Node like document.getElementsByName?

Egor Ushakov

  • Username: erop
  • Joined: Tue Jul 12, 2011 7:51 am
  • Posts: 2
  • Offline
  • Profile

Re: How to get Node by element's name

Post Posted: Fri Mar 23, 2012 2:54 am
+0-
It looks like working selector is
Code:
var node = Y.one('select[name="assigned_user_id_advanced[]"]');

Nick Husher

YUI Contributor

  • Offline
  • Profile

Re: How to get Node by element's name

Post Posted: Fri Mar 23, 2012 7:57 am
+0-
I don't know how important performance is, but this might be a bit faster:

Code:
var node = Y.one(document.getElementsByName('assigned_user_id_advanced[]')[0]);

Ryuichi Okumura

YUI Contributor

  • Username: okuryu
  • Joined: Mon Dec 07, 2009 6:19 am
  • Posts: 11
  • Location: Tokyo, Japan.
  • Twitter: okuryup
  • GitHub: okuryu
  • Gists: okuryu
  • IRC: okuryu
  • Offline
  • Profile
Tags:

Re: How to get Node by element's name

Post Posted: Fri Mar 23, 2012 6:34 pm
+0-
It's probably most likeness document.getElementsByName().

Code:
Y.all('*[name="assigned_user_id_advanced[]"]').item(0);


How's that?

charles williams

  • Username: williamscharles71
  • Joined: Sat Mar 24, 2012 9:30 pm
  • Posts: 1
  • IRC: williamscharles71
  • Offline
  • Profile
Tags:

Re: How to get Node by element's name

Post Posted: Sun Mar 25, 2012 11:57 pm
+0-
this was more like it Ryuichi. :)

PQR

  • Joined: Mon Jan 02, 2012 1:07 pm
  • Posts: 37
  • Offline
  • Profile

Re: How to get Node by element's name

Post Posted: Tue Mar 27, 2012 12:12 am
+0-
Ryuichi,

Can I relace Y.all with Y.one?

Code:
Y.one('*[name="assigned_user_id_advanced[]"]');

Ryuichi Okumura

YUI Contributor

  • Username: okuryu
  • Joined: Mon Dec 07, 2009 6:19 am
  • Posts: 11
  • Location: Tokyo, Japan.
  • Twitter: okuryup
  • GitHub: okuryu
  • Gists: okuryu
  • IRC: okuryu
  • Offline
  • Profile

Re: How to get Node by element's name

Post Posted: Tue Mar 27, 2012 4:23 am
+0-
PQR,

Right, if you need single and first element by selector.
  [ 7 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum