2011-05-04 124 views
1

只是想知道你是否可以提供幫助。jQuery選擇問題

我有下面的代碼位:

<transform DEF='veyron_colour_change' rotation='0.2815 -0.6785 0.6785 -3.69' scale='0.2107 0.2107 0.2107' translation='-2.291 26.33 19.26'> 
    <shape> 
    <appearance> 
     <material ambientIntensity='1' diffuseColor='1 0.1255 0.1255' shininess='0.3825' specularColor='1.215 1.215 1.215'></material> 
    </appearance> 
    <indexedFaceSet creaseAngle='1' DEF='veyron_colour_change-FACES'... 

我試圖選擇以改變diffuseColor屬性使用jQuery的材料元素。代碼即時試圖做到這一點是:

$('[DEF="veyron_colour_change"]').next('[diffuseColor]').attr('diffuseColor', '0.2118 0.1569 0.9333'); 

但它沒有工作。有任何想法嗎?

感謝

回答

1

我想你想.find()沒有.next()

$('[DEF="veyron_colour_change"]').find('[diffuseColor]').attr('diffuseColor', '0.2118 0.1569 0.9333'); 

與屬性的元素(在這種情況下,<material />)是<transform />元素的後代,讓你用.find()定位它。 .next()表示它在之後出現而不是出現在之內它。