Reputation: 6544
Markup::
<td class="info2 gensmall">
<span class="new1">In total there is <strong>1</strong> user online :: 1 Registered, 0 Hidden and 0 Guests </span>
<span class="new2">We have <strong>4</strong> registered users</span>
<span class="new3">The newest registered user is <strong><a href="/u5">cldtomhil</a></strong></span>
<span class="new4">Our users have posted a total of <strong>12</strong> messages</span>
</td>
Ok guys trying to learn the jQuery .split
$(document).ready(function(){
var a = $('td .info2 .new1');
var b = $('td .info2 .new2');
var c = $('td .info2 .new3');
var d = $('td .info2 .new4');
var w = a.split("<strong>");
var x = b.split("<strong>");
var y = c.split("<strong>");
var z = d.split("<strong>");
$('.new1').html('<span>"w"</span> Users Online');
$('.new2').html('<span>"x"</span> Total Users');
$('.new3').html('<span>"y"</span> Newest Member');
$('.new4').html('<span>"z"</span> Total Messages')
});
Ok I know I am doing this wrong just by looking at it. Though I just can't figure out how to use the split feature, I am trying to gain the information inside the <strong>
tags. Then once I have it I want to change the innerHTML basically with the new data like I posted with the .html
Yes I know it's a lot of variables but hey what can you do, I'm not a very good coder yet, and still learning some things so.
Upvotes: 0
Views: 57
Reputation: 272096
Here is how you gain the value:
$('td.info2 .new1 strong').text(); // returns "1"
$('td.info2 .new3 strong').text(); // returns "cldtomhil", not "<a href="/u5">cldtomhil</a>"
Etc. Having said that, String.split is a JavaScript function that splits strings given a separator. What you were trying to do was to grab the contents of an HTML element. There is no need to use string functions to do this. Use DOM functions (or jQuery) to manipulate the DOM.
Upvotes: 4