2017-03-10 10 views
0

는 어떻게 든이 userscript 대신 아이의 부모에 속성을 추가 할 것 같다JQuery와는 아동에 추가

이 제발 도와주세요 c를가 그 일을 왜 이해하기 :

// ==UserScript== 
// @name  GMod Cinema Porn 
// @namespace Bluscream 
// @version  1.0 
// @description H3H3 
// @author  Bluscream 
// @include  https://www.youtube.com/embed/OiMTuwS3xvg* 
// @include  http://cinema.pixeltailgames.com/search.html 
// @include  * 
// @grant  unsafeWindow 
// @grant  GM_xmlhttpRequest 
// @require  https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js 
// @run-at  document-end 
// ==/UserScript== 
(function() { 
    'use strict'; 
    if (window.location.href.startsWith("https://www.youtube.com/embed/OiMTuwS3xvg")) { 
     window.location.href = "http://embed.redtube.com/player/?id=42019&autostart=true"; 
    } else if (window.location.href == "http://cinema.pixeltailgames.com/search.html"){ 
     $ = jQuery || $; 
     $(document).ready(function() { 
      temop = $('#content-container').children('div[style="text-align:center;font-size:0;"]:first'); 
      temop.append('<service>').css('background-image', 'url("http://cdn1-www.craveonline.com/assets/uploads/2013/12/man_file_1048340_youporn-icon.png")').click(function() { 
       window.selectService("YouPorn", "http:\/\/www.youporn.com"); 
      }).hover(function() { 
       window.hoverService(); 
      }); 
     }); 
     //$('#content-container>div[style="text-align:center;font-size:0;"]').append('<service style=\'background-image:url(\"logos\/youtube.png\")\' onclick=\'selectService(\"YouTube\",\"http:\/\/www.youtube.com\")\' onmouseover="hoverService()">-</service>'); 
    } 
})(); 

답변

1

O를 jQuery를 요소 때문에 .append()을 사용하면 방금 추가 한 요소가 아닌 이전 요소를 반환합니다.

속성을 적용하기 전에 첨부 된 요소를 대상으로 지정해야합니다. & 이벤트 리스너; 다음과 같이 :

temop 
    .append('<service>') 
    .find('service:last') 
    .css(/* ... */) 
    .click(/* ... */) 
    .hover(/* ... */); 
+0

Du hier? 단케 :) – Bluscream