admin管理员组文章数量:1332382
I am having an interesting issue. I am using the jQuery function clone()
in a google chrome extension. The function is cloning a table row. The problem is that the TR has some inline javascript/jquery in it using $j()
instead of jQuery()
.
Every time I try to output the cloned row I get the error "$j is not defined".
So I thought of 2 possible solutions for this issue:
- Make my chrome extension work with
$j()
(tried using jquery no conflict) intead ofjQuery()
or
- Do a search in the cloned item before outputting it, replace
$j
withjQuery
.
My problem is that I cannot acplish either...
var rows = jQuery("#field-mapping-template").clone(true);
rows.insertBefore("#field-mapping-template");
I am having an interesting issue. I am using the jQuery function clone()
in a google chrome extension. The function is cloning a table row. The problem is that the TR has some inline javascript/jquery in it using $j()
instead of jQuery()
.
Every time I try to output the cloned row I get the error "$j is not defined".
So I thought of 2 possible solutions for this issue:
- Make my chrome extension work with
$j()
(tried using jquery no conflict) intead ofjQuery()
or
- Do a search in the cloned item before outputting it, replace
$j
withjQuery
.
My problem is that I cannot acplish either...
var rows = jQuery("#field-mapping-template").clone(true);
rows.insertBefore("#field-mapping-template");
Share
Improve this question
edited Jun 20, 2012 at 21:26
David East
32.6k6 gold badges69 silver badges83 bronze badges
asked Jun 20, 2012 at 20:21
user1214678user1214678
4
-
3
Any reason not to write
window.$j = jQuery
? – Douglas Commented Jun 20, 2012 at 20:23 - are you wanting to run the js/jQ when you output the clone or just have it assigned to the page elements? – Jasper Mogg Commented Jun 20, 2012 at 20:37
- Could you show us the code that uses $j()? – David East Commented Jun 20, 2012 at 21:07
- Douglas - using window.$j = jQuery works... but unfotunately this approach on work anyway... because I just noticed that there are other variables in the cloned element that are available in the original script,but that chrome won't recognize. Please post that as the answer to this post and I will mark it as pleted. – user1214678 Commented Jun 21, 2012 at 14:04
1 Answer
Reset to default 5I mean, I wouldn't really remend doing this but you can if you really need to.
Go into the development version of jQuery and scroll all the way down to the bottom until you see this line of code:
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
Now simply change it to:
// Expose jQuery to the global object
window.jQuery = window.$j = jQuery;
Now when you write a script like:
<input type="hidden" name="name" value="test" />
<script type="text/javascript">
$j(function () {
alert($j('input').val());
});
</script>
Instead of $
, it will work for $j
.
This is different than replacing jQuery()
. The $
is short hand for jQuery()
.
I would really, really, really not remend replacing jQuery()
with $j or anything for that matter.
As of the latest release (v1.7.2), there are 879 references to the jQuery
object in the development code that you would have to change to $j
.
If you have a good find and replace, you can do it, but I would not remend doing it.
本文标签: javascriptReplace j with JQueryStack Overflow
版权声明:本文标题:javascript - Replace $j with JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742289742a2447571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论