• Post Reply Bookmark Topic Watch Topic
  • New Topic

hide() method not working in jquery selector  RSS feed

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my code :





This code is not working in my browser means when I click hide button, it does not hide my paragraph in browser.
 
whippersnapper
Ranch Hand
Posts: 1843
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enclose #bi in quotes.

To debug this yourself, you could enter your selector into the browser console and see that it returns nothing. That should tip you off that something is wrong with it. (Actually in this case it results in a syntax error.)
 
Author and ninkuma
Marshal
Posts: 66729
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also having the JavaScript console open would show you the error message.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a word of caution: It may worth your while to spend a bit more time and effort to consolidate your JavaScript skills before diving into jQuery at this point in time.

jQuery is a JavaScript library and using jQuery requires writing JavaScript code, so having a good grasp of JavaScript is essential for using jQuery competently.
It is unreasonable to expect to "pick up JavaScript on the side" by learning jQuery - all you are really doing is investing time and effort into learning jQuery and the jQuery way of doing things.

There is no argument that jQuery is invaluable when working with traditional, non-SPA web applications. It is used with older SPAs written with Backbone.js; even AngularJS 1.x included a jQLite gizmo - but then in the FAQ: Common Pitfalls you'll find this:

Stop trying to use jQuery to modify the DOM in controllers. Really. That includes adding elements, removing elements, retrieving their contents, showing and hiding them. Use built-in directives, or write your own where necessary, to do your DOM manipulation. See below about duplicating functionality.

If you're struggling to break the habit, consider removing jQuery from your app. Really. Angular has the $http service and powerful directives that make it almost always unnecessary. Angular's bundled jQLite has a handful of the features most commonly used in writing Angular directives, especially binding to events.


In fact many people "raised" on jQuery seem to struggle when transitioning to another framework like AngularJS (example - well, they call AngularJS opinionated for a reason).

Also modern JavaScript frameworks like AngularJS 2.x and React tend to implement a shadow or virtual DOM (there is even the minimalistic virtual-dom library). For performance and convenience reasons you are supposed to manipulate the framework's virtual DOM and leave the browser's DOM to the framework - in this situation jQuery cannot be used because it can only manipulate the browser's DOM and not the virtual DOM and jQuery's interference is going to lead to undesirable behavior from the "the other" framework. Typically the "other framework's" mental-model-of-the-browser-DOM is in some way based on the Ye Olde mess of a DOM (though 7 years later things are a little better) - so ultimately there is no escaping the DOM in the browser.

jQuery in Action, 3e; "about this book" p. xxv:

The book assumes a fundamental knowledge of HTML, CSS, and JavaScript ... To top it all off, we have provided an appendix highlighting key JavaScript concepts such as function contexts and closures—essential to make the most effective use of jQuery on our pages—for readers who are unfamiliar with, or would like a refresher on, these concepts.


The 16 page appendix "JavaScript that you need to know but might not!" has to be well understood before venturing into jQuery.

If you don't have access to the book you could try:
YDKJS Up & Going | Kyle Simpson
jQuery Fundamentals - JavaScript Basics | Rebecca Murphey

Understanding JavaScript makes it easier to understand all the JavaScript-related stuff. This is now more important than ever because npmjs/nodejs have become an integral part of the web development tooling pipeline - no help from jQuery here as there is no HTML, CSS, and DOM to deal with; only pure JavaScript and some nodejs. Example: webpack.

So you know jQuery. Now What? | Remy Sharp (2013)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66729
167
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will respectfully disagree. One only needs a fundamental amount of JavaScript knowledge to start using jQuery (hence the appendix in my book), but jQuery doesn't "replace" anything that JavaScript can do. It only makes interacting with the browser easier. I recommend that people start using jQuery as soon as they are able. Otherwise they get bogged down in browser madness which doesn't help at all in learning JavaScript as a language.

In fact, I think using jQuery help people start focusing on JavaScript as a functional language.

Sure, one needs to make sure one is learning JavaScript concepts, but getting bogged down in browser differences and the still-inadequate DOM API doesn't help anyone learn Javascript.
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!