jQuery Problem with serInterval

I have written this script:

$.fn.inters = function (target) {
    this.find('li').hover(function () {
    var head = $(this).find('a').attr('title');
    var image = $(this).attr('title');
    var href = $(this).find('a').attr('href');
    $(target).find('img').attr('src', image);
    $(target).find('img').attr('alt', head);
    $(target).attr('href', href);
    $(target).attr('title', head);
    $(target).find('span').html(head);
}).eq(0).hover();


function headline(){
  $("#topt").inters('.headline');
}

setInterval(headline,3000);


And HTML:

<div class="mhead">
 <div class="mTop"> 
   <a class="headline" title="" href=""> 
     <img alt="" src=""> 
     <span> </span> 
   </a> 
 </div>
<div class="tNav">
 <ul id="topt" class="tUl">
  <li title="http://www.site.com/761028497.jpg"> <a title="" href="">1</a> </li>
  <li title="http://www.site.com/761028497.jpg"> <a title="" href="">2</a> </li>
 </ul>
</div>

the hover effect doesnt repeat with sertInterval. Why sertInterval doesnt work here?

It’s most likely due to a syntax error within your code.

Find the end of the click function, and then try to find the end of the inters function.

have you tried ?

function headline(){
  $("#topt").inters('.headline');
 $("#topt").hover();
}

But first you need to make sure the inters function run without the setInterVal(). Then try my suggestion.

It seems to be a simpler problem than that.
There are opening braces for two of the functions, but only one closing brace.

Proper indentation will clearly show where the closing brace needs to be placed.

Thanks paul;

with :


$.fn.inters = function (target) {
    this.find('li').hover(function () {
    var head = $(this).find('a').attr('title');
    var image = $(this).attr('title');
    var href = $(this).find('a').attr('href');
    $(target).find('img').attr('src', image);
    $(target).find('img').attr('alt', head);
    $(target).attr('href', href);
    $(target).attr('title', head);
    $(target).find('span').html(head);
}).eq(0).hover();

}
function headline(){
  $("#topt").inters('.headline');
}

setInterval(headline,3000);

or

function headline(){
  $("#topt").inters('.headline');
 $("#topt").hover();
}

the hover effect doesnt repeat. Is there any logic fault in my function?

on line 2, “this” should be “$(this)”. Change that, and let us know if there is error. Post the error message.

It’s really to debug JavaScript with firebug, if you haven’t got it, you can download from here Firebug . You need to have firefox in order to use firebug.

Once you’ve installed firebug, open it and refresh the page, if there is error, you can see a red message in firebug pane.

And should tell us what you are trying archive, maybe someone can write up something that can make sense for you.

In above image, 1 2 3 navigation is a list, top section’s data is data from li’s rel and a’ title. With hover, content changes with hover on navigation. The html is:

<div class="mhead">
 <div class="mTop"> 
   <a class="headline" title="" href=""> 
     <img alt="" src=""> 
     <span> </span> 
   </a> 
 </div>
<div class="tNav">
 <ul id="topt" class="tUl">
  <li title="http://www.site.com/761028497.jpg"> <a title="lipsum1" href="">1</a> </li>
  <li title="http://www.site.com/761028497.jpg"> <a title="lipsum2" href="">2</a> </li>
 </ul>
</div>

I use firebug and firefox. There is not error in javascript (I have tested with chrome developer tool too) I want to change 1 2 3 automatic. But I cant with setInterval

Thanks

Ok I see, there a are plenty of premade script to archieve this, just google “image slide with hover”.

I can make simple one for you, but it’s time to off to bed, maybe tomorrow. but do let us know if you found the pre-made script.

And by the way, your html is missing a closing div. 3 divs but there are only 2 closing div

Yes I have seen this but I cant edit…
I have found many scripts like this but all of them, load all items in top div and show, hide them, but in my script content loads with hover.
For example if you have 20 item in navigation, all of 20 content doesnt load at once and only load by hover.
This script works very good but has not automation.
BTW, Im newbie in js…
Many thanks for your help.