RedXTech RedXTech - 1 year ago 83
HTML Question

Change Text of Array Of links in jQuery

For my school's website they have a dropdown list of courses that you're currently enrolled in on the home page. However, if you see it, it is cluttered full of letters that many people might not want to see.

I already know how I'm going to do this. I'm going to use jQuery to select each list item:

var links = $(".d2l-datalist li .d2l-course-selector-item .d2l-left .vui-link");

This returns an array of
elements in text form.

I can set the text of all of them to "Boo!", but I want to change each one individually, using a for/in loop to itterate through each
and change the text depending on what the value of the

However, whenever I do this, since the items in the array are strings, I cannot do anything to them with jQuery.

Any help with this is appreciated :)

Here's my code so far (running from a
from a JS bookmarklet):

var links = $(".d2l-datalist li .d2l-course-selector-item .d2l-left .vui-link");

var count = 1;
for (var link in links) {
link.text("Boo #" + count);
count += 1;

Relevant markup:

Answer Source

You can use the jQuery .each iterator function.

var links = $(".d2l-datalist li .d2l-course-selector-item .d2l-left .vui-link");

var count = 1;

links.each(function() {
    $(this).text("Boo #" + count++);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download