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 of jQuery()
or
- Do a search in the cloned item before outputting it, replace
$j
with jQuery
.
My problem is that I cannot accomplish either...
var rows = jQuery("#field-mapping-template").clone(true);
rows.insertBefore("#field-mapping-template");
I mean, I wouldn't really recommend 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 recommend 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 recommend doing it.