Some words pass from search, I want to wrap them with a div then click one link, remove the outer wrap, but my code not worked for wrap and unwrap. What is wrong?
<?php $_GET['search']='this is a text'; ?>
<script type="text/javascript" src="../jquery.js" ></script>
<script>
$(document).ready(function() {
var words = '<?php echo $_GET['search']; ?>';
$(words).wrap('<div id="words" />');
$('body').append(words);
$('#click').click(function(){
$(words).unwrap('<div id="words" />');
});
});
</script>
<body>
<a id="click">remove me</a>
</body>
words can’t be a string wrap only works on a jquery object, or a dom element.
try something like this: