Skip to main content

Posts

Showing posts with the label filter

jQuery - filter element based on .data() key/value

Say I have 4 div elements with class .navlink , which, when clicked, use .data() to set a key called 'selected' , to a value of true : $('.navlink')click(function() { $(this).data('selected', true); }) Every time a new navlink is clicked, I would like to store the previously selected navlink for later manipulation. Is there a quick and easy way to select an element based on what was stored using .data() ? There don't seem to be any jQuery :filters that fit the bill, and I tried the following (within the same click event), but for some reason it doesn't work: var $previous = $('.navlink').filter( function() { $(this).data("selected") == true } ); I know that there are other ways to accomplish this, but right now I'm mostly just curious if it can be done via .data() . Thanks. Source: Tips4all

How to use keywords to filter a JSON array object?

I am trying to find a way to take an array of keywords that are user createda and filter a JSON array, and have the results appended to the screen. Below is the actual code I am using. var keywords= []; var interval = ""; var pointer = ''; var scroll = document.getElementById("tail_print"); $("#filter_button").click( function(){ var id = $("#filter_box").val(); if(id == "--Text--" || id == ""){ alert("Please enter text before searching."); }else{ keywords.push(id); $("#keywords-row").append("<td><img src=\"images/delete.png\" class=\"delete_filter\" /> " + id + "</td>"); } } ); $(".delete_filter").click( function(){ ($(this)).remove(); } ); function startTail(){ clearInterval(interval); interval = setInterval( function(){ $.getJSON("ajax.php?function=tail&pointer=" + p

Filter array in PHP using keywords?

What could I add to the following code to filter the returned results using keywords in an array? The code that send the keywords, and made the funciton call is in Javasript. The code below opens a file, takes a pointer using a request, opens the file finds the pointer, and retrieves all log lines from the pointer to the end of the file. Then it formats it into a JSON object and sends back to Javacript. function tail(){ $keywords = json_decode($_REQUEST['keywords']); $file = "/path/to/the/log.log"; $handle = fopen($file, "r"); clearstatcache(); if ($_REQUEST['pointer'] == '') { fseek($handle, -1024, SEEK_END); } else { fseek($handle, $_REQUEST['pointer']); } while ($buffer = fgets($handle)) { $log .= $buffer . "<br />\n"; } $output = array("pointer" => ftell($handle), "log" => $log); fclose($handle); echo json_