2011-04-18 6 views
0

한 div의 특정 텍스트를 다른 div로 복사 할 수 있기를 원합니다.특정 div의 특정 텍스트를 다른 div로 복사

텍스트는 Wordpress Plugin에서 생성되며 다음과 같은 클래스 1이 .voting 비활성이고 두 번째 div가 .voting 인 두 개의 div가 생성됩니다.

생성 된 텍스트는 다음과 같이 보일 것입니다 : Rating 4.5/5, 나는 단지 4.5 또는 어떤 투표가 생성 되더라도 결과를 멋지게 표시하기 위해 div로 복사하려고합니다.

도움이 될 것입니다.

+0

안녕하세요 폴 :-) 모든 답변에 대한 감사를 working- 얻을 관리, 그리고 문제를 플러그인 워드 프레스있다? –

답변

0

HTML

<div id="this">Sometext</div> 
<div id="that"></div> 

스크립트

$(document).ready(function() { 
    $("#that").html($("#this").html()); 
}); 
0

이 시도 :

var vote = $(".voting").text().split("/")[0]; 
2

나는이 일에 @Starx과 함께 있어요. 그러나 조금 더 명확하게하려면 : 1

<div> 
    Rating 
    <span id="average">4.5</span>/ 
    <span id="highest_possible">5</span> 
</div> 

<div id="target"> 
    <!-- This could be any element --> 
</div> 

하는 데 도움이 JS

$(document).ready(function() { 
    $("#target").html($("#average").html()); 
}); 

희망을!

1

는 마음이 디스플레이 이름을 변경

<html> 
<head> 

<style type="text/css"> 
#target-rating{font-size:30px; text-align:center; font-weight:bold;} 
</style> 

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script> 

<script type="text/javascript"> 
/*$(document).ready(function() { 
     //var arrayOne = $('.voted').html().split('/'); 
     var arrayOne = $('div[class*="voted"]').html().split('/'); 
     var arrayTwo = arrayOne[0].split(' '); // arrayTwo[1] contains ie: 4.4 
     $('#target-rating').html(arrayTwo[1]); 
});*/ 
</script> 

<script type="text/javascript"> 
// This works for 2 divs 
$(function() { 
     var rating = $('div.inactive,div.voted inactive').text().replace(/^.*: ([\d\.]+).*$/, '$1'); // Extract the rating 
     $('#target-rating').text(rating); // And copy 
}); 
</script> 

</head> 
<body> 
<div id="target-rating"></div> 

<!-- Example divs --> 
<div class="inactive" id="gdsr_mur_text_796_1">Rating: 4.4/<strong>5</strong> (5 votes cast)</div> 
<div class="voted inactive" id="gdsr_mur_text_796_1">Rating: 5.0/<strong>5</strong> (5 votes cast)</div> 

</body> 
</html> 
0
<a class="hello">Copy It</a> 
<a class="goodbye"></a> 


(function($) { 
    $('.hello').click(function() { 

     $(this).clone().appendTo(".goodbye"); 
    }); 
})(jQuery); 
관련 문제