Copy certain text from one div into another div


I want to be able to copy certain text from one div into another div.

The text is generated from a Wordpress Plugin, and it generates 2 different divs, with the following classes 1 called .voting inactive and the second one called .voting.

The text generated is rating based is it will look something like: Rating 4.5/5, i ONLY want to take the 4.5 or whatever vote is generated and copy that into a div to display the result nicely.

Any help would be great.


I'm with @Starx on this one. But just to be a little more clear:

<div> Rating <span id="average">4.5</span>/ <span id="highest_possible">5</span> </div> <div id="target"> <!-- This could be any element --> </div>

Then the JS

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

Hope that helps!


Managed to get it working- thanks for all your answers :-)

<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>


Try this:

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


An example


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


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


<a class="hello">Copy It</a> <a class="goodbye"></a> (function($) { $('.hello').click(function() { $(this).clone().appendTo( ".goodbye" ); }); })(jQuery);


  • complex annotate on django query set
  • Why does the first run of “XCTestCase -measureBlock:” takes so much time?
  • Taking mean across rows grouped by a variable in numpy
  • Neo4j: Filter nodes based on aggregate function
  • C: Incompatible pointer type initializing
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • Assign variable to the value in HTML
  • How to use carriage return with multiple line?
  • Insert into database using onclick function
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Shallow update not allowed (git > 1.9)
  • Perl system calls when running as another user using sudo
  • Weird JavaScript statement, what does it mean?
  • jquery mobile loadPage not working
  • Web-crawler for facebook in python
  • Apache 2.4 - remove | delete | uninstall
  • How to delete a row from a dynamic generate table using jquery?
  • Python: how to group similar lists together in a list of lists?
  • How to include full .NET prerequisite for Wix Burn installer
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Free memory of cv::Mat loaded using FileStorage API
  • Trying to get generic when generic is not available
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • How to stop GridView from loading again when I press back button?
  • Qt: Run a script BEFORE make
  • How to get Windows thread pool to call class member function?
  • Bitwise OR returns boolean when one of operands is nil
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Django query for large number of relationships
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal