Side navigation
#8505 closed bug (invalid)
Opened March 11, 2011 05:18PM UTC
Closed March 25, 2011 08:22PM UTC
Last modified April 07, 2011 03:31PM UTC
replaceWith() call despite empty result set from selector
Reported by: | Jakob Jonas | Owned by: | Jakob Jonas |
---|---|---|---|
Priority: | undecided | Milestone: | 1.next |
Component: | unfiled | Version: | 1.5.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
With this HTML
<body> <div id="XXX">123</div> </body>
executing the following jQuery, the first statement matches and replaces the content with a (missing) image. The second statement does not match its selector but still attempts to load the image even though it is not going to be used
$("123").replaceWith('<img src="http://www.bbc.co.uk/asdasdsdsd.jpg" />'); $("456").replaceWith('<img src="http://www.bbc.co.uk/aasdqerwqeqwe.jpg" />');
If the replaceWith HTML was a trigger to a server side action, this could create havoc for someone whose code works in this way.
Attachments (0)
Change History (4)
Changed March 11, 2011 06:11PM UTC by comment:1
owner: | → Jakob Jonas |
---|---|
status: | new → pending |
Changed March 25, 2011 08:22PM UTC by comment:2
resolution: | → invalid |
---|---|
status: | pending → closed |
Please note that as per my original message on this ticket, it looks like you were attempting to use the XXX selector incorrectly. Rather than querying with $("XXX"), please use $("#XXX") if you wish to select based on an ID. Closing this ticket unless a further test case or comments become available.
Changed March 31, 2011 09:51AM UTC by comment:3
Replying to [ticket:8505 Jakob Jonas]:
With this HTML
<html> <head> </head> <body> <div id="XXX">123</div> </body> </html>
executing the following jQuery, the first statement matches and replaces the content with a (missing) image. The second statement does not match its selector but still attempts to load the image even though it is not going to be used
$("#XXX").replaceWith('<img src="http://www.bbc.co.uk/asdasdsdsd.jpg" />'); $("#YYY").replaceWith('<img src="http://www.bbc.co.uk/aasdqerwqeqwe.jpg" />');
If the replaceWith HTML was a trigger to a server side action, this could create havoc for someone whose code works in this way.
Changed April 07, 2011 03:31PM UTC by comment:4
_comment0: | Agree with Jakob Jonas - something seems amiss to me, too. When passing a function to replaceWith the problem is even more sinister. See http://jsfiddle.net/xjUWd/2/ \ \ Since this ticket is closed I may create a new one and reference this one. → 1302190460079528 |
---|
Agree with Jakob Jonas - something seems amiss to me, too. When passing a function to replaceWith the problem is even more sinister. See http://jsfiddle.net/xjUWd/2/
Did a little searching and I believe this issue is the same as:
Thanks for submitting a ticket to the jQuery Bug Tracker. Could you please provide us with a complete test case that reproduces the issue you're experiencing on jsFiddle.net?.
I've just tried here and I'm unsure of whether you're actually trying to treat XXX as a valid selector in $('XXX') or if you're actually treating the XXX as an ID and using # prior to this.
Also, if you're going to attempt to access an element which may or may not exist, you can handle this manually by simply checking for the existence of the element before trying to call replaceWith. In my opinion this is something which should be handled outside jQuery (if absolutely) needed, but we'll await your test case.