I am trying to swap two spans that belong to a list. One span contains a first name, and the other contains a last name.
I wrapped the first name and last name in their own spans, and then the entire name in a span. Here is the code.
So, lots of spans. The entire thing is wrapped in a span, to accommodate for my use of tinySort, a jQuery plugin that alphabetizes the names. When citing papers, the first authors name needs to be presented as "LastName, FirstName", and then the others are "Firstname Lastname".
So, what I am trying to do is find the first span.authorsname in each list (li) item, then swap the span.firstname with span.lastname.
Here is the page I am working on:
http://cs-www.cs.yale.edu/c2/index.php/ … techniques
I kept plugging away at it…and came up with this solution.
I am sure there is a better way to do this…but, this works, and I am happy with that.
not sure if this is a better solution, but it is more ‘dynamic’ It’s just a slight variation.
It finds the span with a class of "authorsname" then for each it finds, it finds the "firstname", and "lastname" spans and stores the as variables (grabs the element not just the html markup of it.)
It then removes the "firstname" span it found, and adds it after the "lastname" span, then adds the ", " separator for better formatting/readability. (so the name shows up Smith, John instead of SmithJohn.) I don;t know enough jQuery to know why that last part had to be reversed, but if you switch it you get "Lastname1Firstname1, " so I just went with what works.
If anyone can explain that, I’d like to know…
Anywho, this way you can change what is in the span tags (the names) and it will still work… (heck you could even change them from span tags to say div tags if needed (or in theory any other nestable elements). )
EDIT: I didn’t read that it only needed to be the first element so I updated the code now to select only the first element….
You must be logged in to reply to this topic.