. javascript splice. Splice . , .
jQuery, , html. , , , , "dynamic":
var header = $("h1.dynamic").text();
=> "Header with some other stuff"
var header_as_array = header.split(" ")
=> ["Header", "with", "some", "other", "stuff"]
var first_half = header_as_array.splice(0, header_as_array.length/2)
, , :
first_half = ["Header", "with"]
header_as_array = ["some", "other", "stuff"]
:
var first = '<span class="first_half">'+first_half.join(" ")+'</span>';
var second = '<span class="second_half">'+header_as_array.join(" ")+'</span>';
var finished = first+" "+second;
, jQuery:
$("h1.dynamic").html(finished);
, , . , :
var splice_location = Math.ceil(test_as_array.length/2);
var first_half = header_as_array.splice(0, splice_location);
, , .