Found 10711 Articles for Web Development

How to replace the content of an element using jQuery?

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

474 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

How to get the value of div content using jQuery?

Alex Onsman
Updated on 22-Oct-2023 03:22:10

24K+ Views

To get the value of div content in jQuery, use the text() method. The text() method gets the combined text contents of all matched elements. This method works for both on XML and XHTML documents.ExampleYou can try to run the following code to get the value of div content using jQuery:Live Demo $(document).ready(function() {    $("#button1").click(function() {      var res = $('#demo').text();      alert(res);    }); }); This is demo text. Get

How to get HTML content of an element using jQuery?

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

16K+ 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

How can I get the selected value of a drop-down list with jQuery?

Alex Onsman
Updated on 17-Dec-2019 08:18:58

7K+ Views

With jQuery, it’s easy to get selected text from a drop-down list. This is done using the select id. To change the selected value of a drop-down list, use the val() method.ExampleYou can try to run the following code to learn how to change the selected value of a drop-down list. Here, we have a default select option first, but the alert shows the second option, which have been changed using the val method():Live Demo           jQuery Selector                          $(document).ready(function() {       ... Read More

How to redirect to another webpage using jQuery?

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

3K+ 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');        });                    

How to animate scrollLeft using jQuery?

Alex Onsman
Updated on 17-Dec-2019 07:43:36

2K+ Views

To animate scrollLeft using jQuery, use the animate() method with scrollLeft.ExampleYou can try to run the following code to learn how to animate scrollLeft using jQuery:Live Demo $(document).ready(function(){     $('#scrollme').click(function() {     $('html,body').animate({         scrollLeft: $('#demo').css('left')     }, 500, function() {         $('html, body').animate({             scrollLeft: 0         }, 500);     }); }); }); #demo {     width: 100px;     height: 100px;     background: green;     position: relative;     left: 800px; } Click to scroll left

How to find horizontal Scroll Position using jQuery?

Alex Onsman
Updated on 17-Dec-2019 07:42:34

1K+ Views

To find horizontal scroll position, use the jQuery scrollLeft() method.ExampleYou can try to run the following code to find horizontal scroll position using jQuery.Live Demo               jQuery scrollLeft() method                              $(document).ready(function(){             $("div.demo").scrollLeft( 200 );                             $("div.demo").mousemove(function () {                var left = $("div.demo").scrollLeft();                $("#result").html("left offset: " + ... Read More

How to position horizontal scroll bar at center of DIV?

Alex Onsman
Updated on 17-Dec-2019 07:41:36

3K+ Views

To position horizontal scroll bar at center of div, use the scrollleft. You can try to run the following code to position horizontal scroll bar in div.ExampleThe scroll bar is positioned at center of div:Live Demo               jQuery Scroll                              $(document).ready(function(){                         $(document).ready(function(){             var outerContent = $('.demo');             var innerContent = $('.demo > div');                         outerContent.scrollLeft( (innerContent.width() - outerContent.width()) / 2);                 });                          });                             html, body, div {             margin:0;             padding:0;         }         .demo {             width:400px;             overflow-x:scroll;         }                 #viewContainer {             height:120px;             width:1000px;             display:table;         }         .myclass {             width:250px;             height:100%;             display:table-cell;             border:2px solid blue;         }                               Far left     left     center     right     Far right      

How to scroll to element in horizontal div using jQuery?

Alex Onsman
Updated on 10-Dec-2019 06:14:49

1K+ Views

To scroll to element in horizontal div, use the scrollleft.ExampleYou can try to run the following code to learn how to scroll to element in jQuery:Live Demo               jQuery Scroll                              $(document).ready(function(){            document.addEventListener('DOMContentLoaded', function () {               var frames = document.getElementById('frames');               frames.addEventListener('click', function (e) {                  if (e.target.classList.contains('item')) {                    e.target.parentNode.scrollLeft = e.target.offsetLeft;                  }              });           });                          });                                   .myclass {             width: 300px;             display: flex;             position: relative;             overflow-x: scroll;         }             .item {             width: 400px;             background: #FFB563;             margin-right: 40px;         }                                     demo1         demo2         demo3         demo4         demo5         demo6         demo7         demo8            

Advertisements