Install ReactJs on Codeanywhere

The way I did:

  • Log in to https://codeanywhere.com
  • Create a blank container by clicking File > New Connection > Container
  • Choose “Blank Development Stack” Ubuntu OS
  • It will open two tabs
  • Copy Container related information somewhere.  This information will have web address. This is the address you’ll need to view your application.
  • Go to terminal (this should be first opened tab)
sudo apt-get update
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash - 
sudo apt-get install nodejs
sudo apt-get install npm 
sudo npm install -g create-react-app 
create-react-app my-react-app 
cd my-react-app 
npm start

You’ll see http://localhost:3000 in your terminal. Ignore that. Use the web address you have copied before.

Happy coding!

jQuery: Using window url parameter

Let’s say we have passed a parameter to URL: www.mysite.com/?page=test

To collect the data form parameter we can use this function:

function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};

use of this code:

getUrlParameter('page');

or

if (getUrlParameter('page') == 'test'){
// do something
}

jQuery item / image slider

VIEW RESULT IN FULLSCREEN

Select random element using jQuery

Everytime you refresh, it will select random element & show it’s class

Removing CSS file link dynamically

Here style.css is already exist on the top of the file.
I am using just one line jQuery code to remove the CSS.

$('link[rel=stylesheet][href*="/wcsstore/abc/mobile/css/style.css"]').remove();

Javascript: change div or span content

document.getElementById("imageid").src="../template/save.png";
document.getElementById("myAnchor").innerHTML = "Shohag Bhuiyan";
document.getElementById("myAnchor").href = "http://www.shohagbhuiyan.com";
document.getElementById("myAnchor").target = "_blank";

Accessing variables from other functions without using global variables


var MyApp = {}; // Globally scoped object
function foo(){
MyApp.color = 'green';
}
function bar(){
alert(MyApp.color); // Alerts 'green'
}

JS: Hide Something