Reputation: 67
I wonder how can I be adding a tag
for example, the word "John" in my div.
I am using jquery selector contains my problem to give this one. Append it. Follows the code of my page:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Beta style</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div>John Resig</div>
<div>George Martin</div>
<div>Malcom John Sinclair</div>
<div>J. Ohn</div>
<script>
$("div:contains('John')")*.append("<p></p>")*
</script>
</body>
</html>
Upvotes: 1
Views: 350
Reputation: 67207
Try to use jquery's .wrapInner()
function to accomplish your task,
$('div:contains("John")').wrapInner('<p></p>');
Upvotes: 2