Like SystemiConnectFri 15 Oct 2021, 04:50
Auto Save MessagesLGforumFri 26 Feb 2021, 13:31
New tutorial questionTheCrowMon 15 Feb 2021, 08:12
Support iOS Emojis (and other platforms)LGforumSun 14 Feb 2021, 01:25
LGforum (2806)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
Mr.Easybb (1587)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
Bloodbath (745)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
Rukiafan (533)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
Dom (513)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
puppycheese (446)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
pedro (330)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
Neymar (301)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
Hitsu (281)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 
Flora (275)
CSS Variable Selecting Vote_lcapCSS Variable Selecting Voting_barCSS Variable Selecting Vote_rcap 


CSS Variable Selecting

gillgill
Status : Syntax highlighter's colors are nice.

Posts : 78
Join date : 2014-04-05
Sat 07 Mar 2015, 04:03
So I have this code..

Code:
[panda=js]$(document).ready(function() {
 jQuery.get('/privmsg?folder=inbox', function(data) {
  var ibx = data.getElementsByClassName('inbox');
  var lngt = ibx.length;
  if(lngt++) {
  var toast = document.createElement('div');
  var content = '<b>You have new message!</b>'
  toast.appendChild(content);
  }
 });
});

How can I style it with CSS?

Code:
[panda=css]#toast { position:fixed; background:#000; font-family:courier; }
avatarNewbie JS
Status : No status yet...

Posts : 30
Join date : 2015-01-23
Age : 35
Location : England
Sat 07 Mar 2015, 04:15
Why did you make a [ic]$(document).ready(function() {[/ic] when it's completely unnecessary to use there. If you didn't use any jQuery components then don't use that except [ic]$.get[/ic] and [ic]$.post[/ic]

Here's the total fix for your code

Code:
[panda=js]jQuery.get('/privmsg?folder=inbox', function(data) {
  var ibx = data.getElementsByClassName('inbox');
  var lngt = ibx.length;
  if(lngt += 1) {
  var toast = document.createElement('div');
  var content = '<b>You have new message!</b>';
  toast.appendChild(content);
  toast.style.background = "#000"; // or whatever
  }
});

Or if you intend to use jQuery then don't remove the document ready just style it with jQuery.

So this is the fix

Code:
[panda=js]$(document).ready(function() {
 jQuery.get('/privmsg?folder=inbox', function(data) {
  var ibx = data.getElementsByClassName('inbox');
  var lngt = ibx.length;
  if(lngt++) {
  var toast = document.createElement('div');
  var content = '<b>You have new message!</b>'
  toast.appendChild(content);
  $(toast).css('font-family','courier');
  }
 });
});

If you want to style the variable [ic]toast[/ic] with CSS I didn't really sense the right answer for it.
BloodbathBloodbath
Status : No status yet...

Posts : 745
Join date : 2013-05-31
Age : 28
Sat 07 Mar 2015, 04:35
"#toast" matches an element by the id "toast", and handily enough, you can simply assign ids to element nodes by accessing their .id property, so for your code this would be:

Code:
var toast = document.createElement("div");
toast.id = "toast";
// ... your code here
gillgill
Status : Syntax highlighter's colors are nice.

Posts : 78
Join date : 2014-04-05
Sat 07 Mar 2015, 06:11
Thank you both JS & Bloodbath ^^ will try it ASAP
avatarGuest
Thu 05 May 2016, 04:49
@gill Is this solved now?
gillgill
Status : Syntax highlighter's colors are nice.

Posts : 78
Join date : 2014-04-05
Sat 04 Jun 2016, 10:55
Sure! You can Archive this now.
Sponsored content