Answered by:
Custom Selectors

Question
-
User-1826049516 posted
Hi,
I am doing this:
$( function() { $.expr[':'].exact = $.expr.createPseudo( function( input ) { return function( elem ) { return $( elem ).text() === $.trim( input ); } } ); $.expr[":"].expanded = $.expr.createPseudo( function() { return function( elem ) { return $( elem ).css( "display" ) === "none"; } } ); } );
These work fine if they are in $( document ).ready but in pageLoad() I get this in the console:
Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: expanded
Are custom selectors not available in pageLoad()? I use UpdatePanels so need them to be!!
Thanks
Monday, July 8, 2019 9:00 PM
Answers
-
User-1826049516 posted
I've binned off pageLoad() and changed to PageRequestManager, which I was already using for other stuff anyway:
var page; $( function() { page = Sys.WebForms.PageRequestManager.getInstance(); page.add_beginRequest( beginRequest ); page.add_endRequest( endRequest ); $.expr[":"].expanded = $.expr.createPseudo( function() { return function( elem ) { return $( elem ).css( "display" ) === "none"; } } ); } ); function endRequest( sender, args ) { pageLoadViewState(); } function pageLoadViewState( requestType ) { count = $.find( ".detailRow:expanded" ).length; // and lots of other code; } $( document ).ready( function() { pageLoadViewState(); // and lots of other code; } );
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 9, 2019 10:19 AM
All replies
-
User-1174608757 posted
Hi Idoodle,
Are custom selectors not available in pageLoad()? I use UpdatePanels so need them to be!!According to your description, could you please tell me what's pageload() mean? You mean
$(document).load(
function
(){})
or page load event in code behind?Then I hope you could share your code in front end and code behind.It will help us to reproduce your problem.
Best Regards
Wei
Tuesday, July 9, 2019 2:23 AM -
User-1826049516 posted
ASP.NET UpdatePanels needs a special function name in JavaScript/jQuery otherwise during an UpdatePanel refresh handlers are not (re)attached:
<!-- $( function() { $.expr[":"].expanded = $.expr.createPseudo( function() { return function( elem ) { return $( elem ).css( "display" ) === "none"; } } ); } ); function pageLoad( sender, args ) { // code here will run during every UpdatePanel refresh / partial postback count = $.find( ".detailRow:expanded" ).length; <-- DOES NOT WORK HERE, "unsupported pseudo" } $( document ).ready( function() { // code here will ONLY run during initial page load
count = $.find( ".detailRow:expanded" ).length; <-- works here, but does NOT run with every UpdatePanel refresh / partial postback } -->Tuesday, July 9, 2019 8:13 AM -
User-1826049516 posted
I've binned off pageLoad() and changed to PageRequestManager, which I was already using for other stuff anyway:
var page; $( function() { page = Sys.WebForms.PageRequestManager.getInstance(); page.add_beginRequest( beginRequest ); page.add_endRequest( endRequest ); $.expr[":"].expanded = $.expr.createPseudo( function() { return function( elem ) { return $( elem ).css( "display" ) === "none"; } } ); } ); function endRequest( sender, args ) { pageLoadViewState(); } function pageLoadViewState( requestType ) { count = $.find( ".detailRow:expanded" ).length; // and lots of other code; } $( document ).ready( function() { pageLoadViewState(); // and lots of other code; } );
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 9, 2019 10:19 AM