<html>
<head>
<script>
remove_line(11);
// This should remove the line 11 from source code,
// eliminating the unordered list element.
</script>
</head>
<body>
<p>Some text</p>
<ul><li>Some list item</li></ul>
<a>Some link</a>
</body>
</html>
I am totally aware that this code hurts your eyes. However, for very atypical technical reasons (performance mostly), this would be the most effective way to solve my problem. It is most likely not doable but it would really save me a lot of coding and performance issues.
If it is not doable (as expected), what is the most consistent/effective notation/technique for uniquely identifying/accessing every elements of the DOM (including text that is mixed/inline with elements).
I was thinking of the following notation: tag_name[index] where index would represent the Xth element by order of appearance in the source code. However, I'm not sure if it's exactly efficient and I'm not sure how to implement it in Javascript. I've also thought of XPath but I'm not sure if it's well supported by Javascript (apart from some frameworks "simulating" it).
UPDATE: My original post wasn't very clear, so I'll clarify some points:
The ultimate goal of the library I'm working on is to "minimize page rendering", so doing it server side and sending it back to the user isn't an option. I'll post an update once I have a functional implementation of what I'm trying to do. Otherwise it'd be too long to explain here.
To clarify what I really need to do, let me give the following (fictional) example:
- Script X is a server side script that randomly selects a DOM node from document.html.
- Script X needs to tell script Y (a Javascript script located in document.html) to delete the DOM node it has selected.
- How does script X uniquely identify the DOM node it has selected so it can communicate it to script Y?
I'm really interested in how to uniquely identify the DOM node so that script Y can identify it and manipulate it. Preferably, it should work with text nodes as well.