OlehZiniak
OlehZiniak

Reputation: 953

How to make or edit a class in JQuery before making an object?

Here's my problem: I have a class defined in CSS:

.myclass {height: 10px; width: 10px}

But in my script file,I append one parent div with the child divs of this class. And the total number and sizes of each div are calculated with jQuery. So the given size 10px is changing. But when the number of divs is higher than 50 my browser crashes, because when I use

$('.#parentDiv').children().last().width(CalculatedSize).height(CalculatedSize);

I pick with every iteration all the div's and rearranging their sizes (If i understand this correctly).

Is there a method to change not the class of each selector each time, but to edit the existing css class in general BEFORE adding elements with this class, and then append a parent div with already redefined in size and number child divs?

Here's the code with which I append my parent div

    while ( i<=N ) {
        $('#parentDiv').append('<div class="myclass"></div>');
        $('#parentDiv').children().last().width(CalculatedSize).height(CalculatedSize);
        i++;

CalculatedSize - is a function.

Upvotes: 2

Views: 52

Answers (1)

OlehZiniak
OlehZiniak

Reputation: 953

But when the number of divs is higher than 50 my browser crashes

turned out that the problem was that i used a FUNCTION to calculate a cell size. When I tried to use variable for it, everything worked much faster.

Upvotes: 2

Related Questions