Trying to get div 1 into div 2 and wrap brackets around the text.
Attempt
$('.div1').append('(' + $('.div2') + ')');
Before
<div class="1"></div>
<div class="2">blah</div>
What I want
<div class="1"><div class="2">(blah)</div></div>
The problem is your selectors: .div1 and .div2, these are searching for elements that have the class of div1 and div2; whereas you want the div elements, with class 1 or 2.
Therefore I'd suggest:
$('div.2').text(function(i,t){
return '(' + t + ')';
});
$('div.1').append($('div.2'));
Although do be aware that using a numeral character as the first character of a class, or id, can be problematic in CSS.
References:
Try this
$(function(){
$('div.2').text('('+$('div.2').text()+')');
$('div.1').html($('div.2'));
});
$(function(){
//$('.div1').append('(', $('.div2'), ')'); //this is better way but you can try following
$('.div1').append($('.div2'));
$('.div2').html('('+$('.div2').html()+')');
});
Try:
var html = $('.div2');
var text = $('.div2').text();
$(html).text("("+text+")");
$('.div1').append(html);
Note:
Name of class never starts with numeric values.
You JS could look like this
$( document ).ready(function() {
$('.1').append('(' + $('.2').html() + ')');
$('.2').remove();
});
Here's a working example. http://jsfiddle.net/cVD6X/
Hopefully this is what you intended.
Regards, Eric Robinson
( and ) but hopefully that shouldn't make a difference.You should clone the element then add the parentesis to it, and append it to the other div. After that you can always remove the old element.
JS
var div2 = $('.div2').clone();
div2.text('(' + div2.text() + ')');
$('.div1').append(div2);
Html
<div class="div1"></div>
<div class="div2">blah</div>
<div class="1">(<div class="2">blah</div>)</div>
div1anddiv2but your example is using elements with the class1and2.