I am trying to load jQuery plugin based on the choice made as shown in the fiddle.
JS
$(document).ready(function()
{
$('img').each(function()
{
var th=$(this);
var className=th.prop('class');
var clas=['type1','type2','type3','type4','type5','type6','type7','type8','type9','type10'];
var choice=((jQuery.inArray(className,clas))*1) + 1;
var str="";
var src=th.attr('src');
var titleText=th.attr('alt');
switch(choice)
{
case 1:
alert('fall under Type1')
str = '<a href="' + src + '" class="cloud-zoom" rel="adjustX: 10, adjustY:-4" target="_blank"/>';
th.wrap(''+str+'');
break;
case 2:
str = '<a href="' + src + '" class="cloud-zoom"';
str+= 'rel="'+"position:'inside', showTitle: false, adjustX:-4, adjustY:-4"+'" target="_blank"/>';
th.wrap(''+str+'');
break;
}
if( choice == 1 || choice == 2)
{
$("head").append("<link>");
css = $("head").children(":last");
css.attr({
rel: "stylesheet",
type: "text/css",
href: "http://www.professorcloud.com/styles/cloud-zoom.css"
});
// In the js file method is invoking on domReady, That is why i am calling manually again on call back after wrapping HTML
$.getScript("http://www.professorcloud.com/js/cloud-zoom.1.0.2.js", function(){
$('.cloud-zoom').CloudZoom();
});
}
});
});
HTML
<img src="http://cdn.tripwiremagazine.com/wp-content/uploads/images/stories/Articles/best-jquery/serie3.jpg" class="type4" alt="jghdhefyhe" height="100px" width="130px">
In the fiddle method invocation is written under domReady. That might be causing the problem, because I am wrapping custom HTML to make that plugin work. Please have a look at the above fiddle.
I think that that problem is that you are trying to load a script from a server on a different domain. You should use $.ajax() and set the option
crossDomaintotrue.