Closed greg84 closed 10 years ago
This is, perhaps counterintuitively, how it's supposed to work. The parameter for remove
is a filter, so it only affects elements that are actually part of the selection. See: http://api.jquery.com/remove/#remove-selector
When you create a DOM using CQ.Create
it returns a CQ object that has the top-level elements selected. So in the 1st example, cq
has two members: a DIV element and a SCRIPT element. So the filter removes only the SCRIPT.
In the 2nd, only the DIV element is actually a member of cq
; the SCRIPT is a child. So the filter will not match it.
An example using jQuery is here.
Makes perfect sense! Thanks for your help.
This is what I needed to do, which of course works fine:
var cq = CQ.Create("<div><script></script></div>");
cq.Find("script").Remove();
return cq.Render();
I'm trying to remove
script
tags from some markup, but it doesn't work if thescript
tag is inside another. When I run this:The output is as expected:
However, when I change it to this:
It doesn't work, the output is the same as the original markup:
Am I doing something wrong or is this a bug?