We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

jQuery - Injecting HTML string into a div element

Medium Priority
743 Views
Last Modified: 2012-06-27
Hello all,

I'm just wondering what the best way is to add and show a chunk of HTML to a div which already exists on the page.

I have a div called "result_list", as the user types a list of results will be returned from search.php

EG:

<ul>
<li>Bananas</li>
<li>People</li>
<li>TV</li>
<li>Cheese</li>
<li>Cinema</li>
</ul>

I want to inject this in to the div element every time they type in the box.

It works so far, I just want to know how to inject/update the HTML in the div

Thanks for assistance,

Luke
// jQuery code so far
	// Handle search result from top menu
	$('#search_term').bind("keyup", function(e) {
		
		// Set the values
		var search_term = $('#search_term').val();
		
		// Set the data string to be sent to the script
		dataString = "search_term=" + search_term;
		
		$.ajax({
			type: "POST",
			url: "ajax/search.php",
			data: dataString, 
			dataType: "html",
			success: function(search_return) {
				$('#result_list').// inject html to existing div

			},
			error: function() {
				alert("not successful");
			}
		});
		
	});

// Already existing div element
<div class="result_list"></div>

Open in new window

Comment
Watch Question

Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.