jQuery 1.5.2 detach = error
I have a problem with the jQuery detach()
function. See the Example page.
The chrome throws this error:
Uncaught TypeError: Object [object Object] has no method 'replaced'
.
and Firefox/Firebug this one:
'c.replace is not a function'
in the jQuery File
The HTML code:
<nav class="menu center">
<ul>
<li><a href="#" data-link="home">Home</a></li>
<li><a href="#">1</a></li>
<li><a href="#">3</a></li>开发者_JS百科
<li><a href="#">5</a></li>
<li><a href="#">6</a></li>
<li><a href="#">7</a></li>
<li><a href="#">X</a></li>
<li><a href="#">Z4</a></li>
</ul>
</nav>
<div id="RTMPClient"><p>text</p></div>
</section>
The JavaScript code:
$(".menu").delegate("a", "click", function() {
var dataValue = $(this).data("link");
var contentDiv = $(".flash");
var flash = $(contentDiv).find("#RTMPClient");
if (dataValue=='home') {
contentDiv.prepend(flash);
} else {
contentDiv.detach(flash);
}
});
Can anyone tell me what is causing this error?
This is not how .detach()
docs works..
the parameter it takes is a selector and not an element. And that selector will filter the original selection (not search inside it)
for example
$('.someclass').detach('.otherclass')
will detach the elements that have both someclass
and otherclass
applied.
It not detach the elements that have otherclass
applied that are inside some other element with class someclass
.
You likely want to do
flash.detach();
but you should save that to a variable if you want to re-insert it a later time.
otherwise just use flash.remove()
精彩评论