Ajay Mohite
Ajay Mohite

Reputation: 119

Can I use jQuery's load() function to load data into a tag's attribute?

Can I do something like this:

$('#myTag').attr('value').load('my_php_file.php');

Upvotes: 0

Views: 92

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039160

No, because .attr('value') returns a string (representing the value of the value attribute on the DOM element) and it is pretty meaningless to call the .load() method on a string. You usually call this method on a DOM element. To illustrate your problem, here's what your code is equivalent to:

var value = 'some value';
value.load('my_php_file.php');

Nonesense.

Did you mean:

$.ajax({ 
    url: 'my_php_file.php', 
    success: function(result) { 
        $('#myTag').val(result); 
    } 
});

Upvotes: 4

Related Questions