Reputation: 59
How can I define a variable x which is true for values form 1 to 100. I have written the code for some idea that how it should work. Please help your valuable time is highly appreciated.
$('.line1').attr("x2", function (d) {
return $('.peak1').attr("x")
});
$('.line2').attr("x2", function (d) {
return $('.peak2').attr("x")
});
$('.line3').attr("x2", function (d) {
return $('.peak3').attr("x")
});
$('.line4').attr("x2", function (d) {
return $('.peak4').attr("x")
});
$('.line5').attr("x2", function (d) {
return $('.peak5').attr("x")
});
// I want to write this function by defining x value from 1 to 100 so that it would work for every equal value.
var x = 1 to 100;
$('.line'+x).attr("x2", function (d) {
return $('.peak'+x).attr("x")
});
Upvotes: 0
Views: 779
Reputation: 7779
If you could provide your HTML then I might give you a working example.
But you just need to loop from x = 1 to 100
for (var x = 1; x <= 100; x++){
$('.line'+x).attr("x2", function (d) {
return $('.peak'+x).attr("x")
});
}
Upvotes: 0
Reputation: 2137
You should make a loop, like this:
for (var i=1; i <= 100; i++) {
$('.line'+i).attr("x"+i, function (d) {
return $('.peak'+i).attr("x")
})
}
Upvotes: 3