Replace Content of an Element using jQuery

Alex Onsman
Updated on 17-Dec-2019 08:12:34

607 Views

To replace the content of an element using jQuery, use the text() method.ExampleYou can try to run the following code to replace content inside a div:Live Demo $(document).ready(function(){   $("#button1").click(function(){     $('#demo p').text('The replaced text.');  }); });        The initial text Replace Text

Get HTML Content of an Element Using jQuery

Alex Onsman
Updated on 17-Dec-2019 08:10:00

18K+ Views

To get HTML content of an element using jQuery, use the html() method. The html() method gets the html contents of the first matched element.ExampleYou can try to run the following code to get HTML content of an element using jQuery:Live Demo $(document).ready(function(){   $("#button1").click(function(){     var res = $('#demo').html();     alert(res);   }); }); This is demo text. Get

Sort By Both Timestamp and Enum in MySQL

AmitDiwan
Updated on 17-Dec-2019 08:06:34

132 Views

For this, you can use ORDER BY DATE(). Let us first create a table. Here, we have a column with type DATE and another with type ENUM −mysql> create table DemoTable    -> (    -> JoiningDate date,    -> Status ENUM('Good', 'Excellent', 'Bad')    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-21', 'Excellent'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Status) values('Bad'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Status) values('Good'); Query OK, 1 row affected (0.13 sec)Display all ... Read More

Redirect to Another Webpage using jQuery

Alex Onsman
Updated on 17-Dec-2019 08:05:24

4K+ Views

To redirect to another webpage in jQuery, use attr().ExampleYou can try to run the following code to redirect to another webpage:Live Demo                          $(document).ready(function() {           $(location).attr('href','https://qries.com');        });                    

Display Only Date from Timestamp Value in MySQL

AmitDiwan
Updated on 17-Dec-2019 08:01:13

236 Views

To display the only date from timestamp value, use the FROM_UNIXTIME() method in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> timestampValue bigint    -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1538332200); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(1577730600); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(1488652200); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

Use SELECT Statement While Updating in MySQL

AmitDiwan
Updated on 17-Dec-2019 07:58:32

364 Views

For this, use sub query along with WHERE clause while using the MySQL UPDATE command. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(250, 'David'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(150, 'Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select ... Read More

Query Results with Less Than X Characters in MySQL

AmitDiwan
Updated on 17-Dec-2019 07:54:29

202 Views

You can use CHAR_LENGTH() along with the WHERE clause. Let us first create a table −mysql> create table DemoTable    -> (    -> FullName varchar(50)    -> ); Query OK, 0 rows affected (1.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.91 sec) mysql> insert into DemoTable values('Robert Miller'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.89 sec)Display all records from the ... Read More

Split a Column in MySQL

AmitDiwan
Updated on 17-Dec-2019 07:53:04

2K+ Views

To split a column, you need to use SUBSTRING_INDEX() in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(40)    -> ); Query OK, 0 rows affected (1.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John_Smith'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values('Carol_Taylor'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('David_Miller'); Query OK, 1 row affected (0.54 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------------+ ... Read More

Add a Single Year to All Date Records in a MySQL Table Column

AmitDiwan
Updated on 17-Dec-2019 07:49:36

219 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> JoiningDate datetime    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2015-01-21'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2017-04-02'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('2018-12-31'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------------+ | JoiningDate         | +---------------------+ | 2015-01-21 00:00:00 ... Read More

Placing Comments in the Middle of a CREATE TABLE Statement

AmitDiwan
Updated on 17-Dec-2019 07:44:06

103 Views

Yes, it is possible using the # symbol. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY , # Creating a sequence Number    -> FirstName varchar(20), # Creating a column to store name    -> Age int # creating a column to store an age    -> ); Query OK, 0 rows affected (1.43 sec)Above, we have set comments using the # symbol. Insert some records in the table using insert command. We will set comments in insert statement as well using the same # symbol ... Read More

Advertisements