Reputation: 3392
I have the HTML in my DOM, you can find the HTML code below. I would like to write the javascript function which return me image and font tags by id. How can I do this?
<ul id="ChatUsers">
<li class="ajaxchat_Available" id="ajaxchat_42">
<img src="http://cash.co/modules/mod_ajaxchat/images/countryflags/us.gif">
<strong>
<a onclick="javascript:chatWith(42, 'us',) 'darkgreen')" href="javascript:void(0)">
<font color="darkgreen"><b> Admin</b></font>
</a>
</strong>
</li>
<li class="ajaxchat_Available" id="ajaxchat_48"
<img src="http://cash.co/modules/mod_ajaxchat/images/countryflags/xx.gif">
<strong>
<a onclick="javascript:chatWith(48, 'xx', '#ff0000')" href="javascript:void(0)">
<font color="#ff0000"> tony</font>
</a>
</strong>
</li>
</ul>
How can I write the function which return me img and font tags by id?
function get_data_by_id(42) {
...
jQuery filter code here...
return {
img: '<img src="http://cash.co/modules/mod_ajaxchat/images/countryflags/us.gif">',
font: '<font color="darkgreen"><b> Admin</b></font>'
}
Thanks!
Upvotes: 0
Views: 166
Reputation: 1831
Try this:
function get_data_by_id(id) {
var img = $( "#ajaxchat_" + id ).find( "img" ).get(0);
var font = $( "#ajaxchat_" + id ).find( "font" ).get(0);
return obj = {
"img" : img,
"font" : font
};
}
Upvotes: 1
Reputation: 300
given that id is the input param
var img = $( "#" + id ).find( "img" ).outerHTML();
var font = $( "#" + id ).find( "Strong a font" ).outerHTML();
return obj = {
"img" : img,
"font" : font
};
Upvotes: 0