I think this might work for you:

(function($){

    $.fn.extend({
        initSlides: function(){
            var t = $(this).attr("id");
            $("#" + t + " img").hide();
        }
    });

    $(document).ready(function(){
        if (!$("div.introbody").length) {
            $(".project").initSlides();
        }
    });

})(jQuery);

Firstly, the self executing function that wraps your plugin had the
incorrect syntax, check out where the dollar sign is now in the first
line, and the last line. That's the pattern you should be using.

Second, you need to wait until the document is ready before you can
look for any elements, I moved the if statement below and wrapped it
in the ready function. This seems to work for me, it hides an image
inside <div class="project" id="test"><img /></div>.

Good luck,
JT

On Jan 14, 12:38 am, knal <knalp...@gmail.com> wrote:
> Hi there,
>
> I have a function/plugin (below this message) which should fire after
> it is checked that div.introbody
> doesn't exist. There is only a single div.project on the page for sure
> but i don't know how to fire the
> function. I've been struggling with this all night! Any help will be
> greatly appreciated!
>
> Thanks, Knal
>
> $(function(){
>
>         if( !$( "div.introbody" ).length ){
>                 $( ".project" ).initSlides()
>         }
>
>         $.fn.extend({
>
>                 initSlides: function() {
>
>                         var t = $(this).attr( "id" )
>
>                         $( "#" + t + " img" ).hide()
>
>                 }
>
>         })});

Reply via email to