Pregunta

Got a bit of a problem... basically using this statement in html with a ul menu to activate it.....

<div id="subnav" >
        <ul>
            <li id="subone"><a href="#">Definitions</a></li>

        </ul>
</div>

   </div>

   <script src="jquery.js"></script>
 <script type="text/javascript">
  $(function(){
 $("#subnav ul li a") .click(function(e){
    e.preventDefault()
    $('#content2').load($(this).attr('abc.html') + ' #content2');
    });
  });
   </script>



  <div id="content2">

  </div>

......... This does nothing and can't seem to work out why....Can someone please tell me where I am wrong here. BTW the abc.html page simply has ....

<html>

<head>
  <link rel="stylesheet" type="text/css" media="all" href="whatis.css" />
 </head>
  <body>
  <div id="content2"><p>this is a test </p></div>
   <div id="content3"><p>Here comes some content </p></div>
   </body>
  </html>

any ideas people ??

cheers, Greg.

¿Fue útil?

Solución

Try this:

$('#content2').load('abc.html #content2');

.attr('abc.html') attempts to return the value of the attribute abc.html... so that would work if your a looked like this:

<a abc.html="something">Definitions</a>

(though that wouldn't be a valid attribute)


Now if your a looked like this:

<a href="abc.html">Definitions</a>

You could do this:

$("#subnav ul li a") .click(function(e){
    e.preventDefault()
    $('#content2').load($(this).attr('href') + ' #content2');
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top