Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply selectivizr after DOM modifications #18

Open
fcsonline opened this issue Jul 1, 2011 · 11 comments
Open

Apply selectivizr after DOM modifications #18

fcsonline opened this issue Jul 1, 2011 · 11 comments

Comments

@fcsonline
Copy link

Hello,

First of all thanks for this great tool.

So, my question is if it's possible to apply the CSS after DOM modifications?

An example:

The HTML file:

<table>
    <tr><td>Row 1</td></tr>
    <tr><td>Row 2</td></tr><!-- Appears red -->
    <tr><td>Row 3</td></tr>
    <tr><td>Row 4</td></tr><!-- Appears red -->
</table>

The CSS file:

tr:nth-child(even) td { background:red;}

The javascript code:

$("<tr><td>Row 5</td></tr>").appendTo("table tbody")
$("<tr><td>Row 6</td></tr>").appendTo("table tbody") 

In this example the 'Row 6' dont' appears in color red, because the style of new nodes is not applied.

Is there a solution?

Thanks!

@keithclark
Copy link
Owner

Currently, there is no automatic solution to this but it is something I'm trying to develop but it's not an easy feature to just "bolt on"

You could manually add the selectivizr classes to your new objects before adding them to the DOM. It's not ideal, but it would allow you to move on.

@arronmabrey
Copy link

I'm also needing this right now too. I'm fine to add the classes manually in the mean time. Do you have any documentation on what classes to add?

@keithclark
Copy link
Owner

The best way to find that out would be to use IE developer tools to see which classes were added to the elements your modifiying. They all begin with slvzr-.

@fcsonline
Copy link
Author

And what about to bind DOMNodeInserted Javascript event and filter the selectivizr targets and then apply the appropriate CSS attributes?

@keithclark
Copy link
Owner

Unfortunately, IE6-8 do not support DOMNodeInserted so that's not possible.

@fcsonline
Copy link
Author

Ouch! , and try to rescan the new nodes manualy. Something like:

$("<tr><td>Row 5</td></tr>").appendTo("table tbody");
$("<tr><td>Row 6</td></tr>").appendTo("table tbody");

$("table tbody").selectivizr(); 
// At this point, all the new nodes in this context have the appropriate CSS attributes

What do you think?

@Osoascam
Copy link

It's actually kind of difficult, as it implies, for example nth-child(3n-2) to keep track of the parent, remove styles to children created and apply the class again just to the ones that match. Not impossible, but requires a bit of thinking

@yatil
Copy link

yatil commented Oct 14, 2011

Tracking this issue as this is something that would have been handy at this very moment :-) Not an easy to do thing though…

@lolmaus
Copy link

lolmaus commented Aug 28, 2013

It would be nice to be able to at least re-run Selectivizr on the whole document...

@PikachuEXE
Copy link

@lolmaus I think #75 could be what you are looking for...

@lolmaus
Copy link

lolmaus commented Oct 27, 2013

@PikachuEXE, i've just tried it and it does work. Thank you. ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants