Jquery

Warning message

JQuery Cycle must be installed in order to run the slideshow. Please go to Status Report for instructions.

Here we will provide posts related to Jquery.

For example we want to remove tag in this line :
techrappers is a very nice tech solution Website.

You can achieve it by two solutions :

1) $('b').contents().unwrap();

In the above Jquery line it will remove the tags and return you with simple string.

2) Or a much faster solution if you are unwrapping lots of a content

$("b").replaceWith(function() { return $(this).contents(); });

To make a certain part clickable and then hide it when you click anywhere else, you need to check if your click place has certain class then show it otherwise hide it.
So we will check our click on whole document and then we will see if it has certain class attached to it or not. Like this :

(function ($) { 
// Check the click on whole DOM
$(document).on('click', function(e) {
       // Check if target has certain class
        if($(e.target).hasClass('YOU_CLASS_NAME')) {
                $('.CLASS_NAME_TO_SHOW_HIDE').show();
        } else {
               $('.CLASS_NAME_TO_SHOW_HIDE').hide();
        }
})
})(jQuery);

To resolve this error you must wrap your JavaScript inside function like this :

(function ($) { 
  // Your jQuery code.
  $('#something1').click(function () {
    $('#something2').slideToggle();
  });
  //Put your code between these comments.
})(jQuery);

To Change the text of a option value with in a text box use the following code :
In below example just change the select id name "edit-field-category-tid option" with your select id and 1,2,3,4 represent the order of terms in selectbox

$("#edit-field-category-tid option").eq(1).text("Bares y Restaurantes");
$("#edit-field-category-tid option").eq(2).text("Grandes Superficies");
$("#edit-field-category-tid option").eq(3).text("Mayoristas");
$("#edit-field-category-tid option").eq(4).text("Al Detal");

OR

$('select option:contains("Online")').text('offline');

Please Note : You can use the above code to change the values on drupal views filter expose form select box. The possible scenario is to change the text on change on language. But for that you have to change
the "Ajax : No " inside your views.

We cannot assign JavaScript variables to PHP directly . To do this AJAX comes into play. You can pass data and variables asynchronously . 

To do this you have to pass HTTP request asynchronously using Jquery Ajax method http://api.jquery.com/jQuery.ajax/ .

To do this first include the Jquery library in your file at the top so that you can use this ajax method . Current version of jquery is 1.10 

you can use this line : <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Then you have to include the code for sending the variable from javascript to PHP.

$.ajax({
  type: "POST",
  url: "save_data.php",
  data: "title="+strTitle+"&name_email="+name_email+"&result="+result,
   cache: false,
})

In above you have defined POST method , so you can receive the values in save_data.php using $_POST variable easily like $_POST['title'] .

In URL save_data.php is the file where you are sending the javascript variables to php, to use or save the data in the database.

Data string can be made by that or like this :

data: { name: "John", location: "Boston" }

In the end set cache to false, so that it cannot cache the url.

and thats it!

Now you can receive values in your php file and can do the operations with your data.

Subscribe to RSS - Jquery