/    Sign up×
Community /Pin to ProfileBookmark

How to shift elements with Jquery

Hi I want to ask somebody if is possible to do this with Jquery:

I have a few select elements in a form:

select A
select B
select C
select D
select E
select F
button X
button Y

In the element select A I choose something what I want to do. Select E is titled “Group”. In the default option of A it has low priority so the E (Group) is on the end of list. But if I change A to next option so priority of E (Group) changes to high. [B]So in this point I need to get the E element instead of position B. [/B] And when I change the select A back to previous option, so I need to get it back to position E.

Do you have some idea how to shift the elements? Maybe is only solution to create recursive function to copy elements to memory, remove elements, resort elements in memory and append the elements from memory back to parent element? Or do you have some simpler way?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jul 28.2010 — I'm not sure what the equivalent jQuery functions are, but with the normal DOM functions, you would do this.var e = /* reference to select E */;
e.parentNode.insertBefore(e.parentNode.removeChild(e),/* Reference to Select C */);
I'm sure jQuery has something similar. [url=http://api.jquery.com/remove/].remove()[/url] from the Docs.
Copy linkTweet thisAlerts:
@crazy_boyauthorJul 28.2010 — Thank you, insertBefore is in Jquery also
×

Success!

Help @crazy_boy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...