0

Don't worry about the vwo__$, it is just jquery used on another system.

First I am creating id's numbered for each, then instead of repeating the code can I make jquery find all id's div.text-right#top-1 up to around 20?

vwo_$.each(vwo_$("div.details div.text-right"), function(ind) {
   vwo_$(this).attr('id', 'top-' + parseInt(ind + 1));
});

var x = 1
vwo_$.each(vwo_$("div.text-right#top-:eq(' + x + ')"), function(x) {
   x++;
   vwo_$(this).append(vwo_$("div.infolist ul:nth-child(1) li:nth-child(1)"));
   console.log(x)
   });

I would like a more efficient for the jquery selector to count.

It doesn't continue looking for ids after #top-1

2

1 Answer 1

0
vwo_$.each(vwo_$("div.details div.text-right"), function(ind) {
    vwo_$(this).attr('id', 'top-' + parseInt(ind + 1));
});

vwo_$.each(vwo_$("div.text-right[id^=top-]"), function(idx, value) {
    vwo_$(this).append(vwo_$("div.infolist ul:nth-child(1) li:nth-child(1)"));
    console.log(idx);
});

Edit:

[id^=top-] ^= indicates "starts with". Conversely, $= indicates "ends with".

The symbols are actually borrowed from Regex syntax, where ^ and $ mean "start of string" and "end of string" respectively.

See the specs for full information.

SOURCE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.