<div id="one">
  <div id="two">hello</div>
  <div id="three">word</div>
  <div id="three">
    <p><a href="#">tonsh</a></p>
  </div>
</div>$("#three").parent()[0].css({'background-color' : 'red', 'font-weight' : 'bolder'});这样搞不行啊 求解

解决方案 »

  1.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://www.wanmei.com/public/js/jq_132.js"></script>
    </head>
    <body><div id="one">
      <div id="two">hello</div>
      <div id="three">word</div>
      <div id="four">
      <p><a href="#">tonsh</a></p>
      </div>
    </div>
    <script language="javascript">
    $("#three").parent().css({'background-color' : 'red', 'font-weight' : 'bolder'});
    </script>
    </body>
    </html>
      

  2.   

    你有两个id都叫three了楼主你想拿到哪个父对像?是最外层的div吗你看看我的代码效果,对吗
      

  3.   

    $("#three").parent() 这样获取的是所有的对象 我要的是获取父对象中的第一个对象
    比如$("#three").parent() 父对象中的第一个对象应该是<div id="two">hello</div>
    而且背景色是红的也应该是这一行才对 怎么才能好做到呢
    js中一般都是getElementsByTagName('span')[0] 而jquery中就不行 
      

  4.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://www.wanmei.com/public/js/jq_132.js"></script>
    </head>
    <body><div id="one">
      <div id="two">hello</div>
      <div id="three">word</div>
      <div id="four">
      <p><a href="#">tonsh</a></p>
      </div>
    </div>
    <script language="javascript">
    $("#three").parent().children('#two').css({'background-color' : 'red', 'font-weight' : 'bolder'});
    </script>
    </body>
    </html>
      

  5.   

    $("#three").parent().children().first().css({'background-color' : 'red', 'font-weight' : 'bolder'});这样不行啊 我的意思就是取父对象中的第一个子对象使其背景色为红色
      

  6.   


    $("#three").parent().children().eq(0).css({'background-color' : 'red', 'font-weight' : 'bolder'});
      

  7.   


    嗯 是这个意思 first()换成eq(0)可以了 谢谢!
      

  8.   

    直接用javascript的parentNode就行啦。。或者getElementsByTagName("xx")[i];