user9371102
user9371102

Reputation: 1276

Hide a <div> with jQuery without using ID or class

I want to hide the following <div> in my site pages, but this <div> is changing its position dynamically, so I cannot use the code $("div:eq(0)").hide();

<div style="background: #ebebeb; border-top: 1px solid #ccc; border-right: 1px solid #ccc;
border-left: 1px solid #ccc; padding: 5px; font-size: 12px; position: fixed; right: 3%; 
bottom: 0px; -webkit-border-radius: 3px 3px 0px 0px; border-radius: 3px 3px 0px 0px;">
Powered by <a href="http://bizmate.in">Bizmate</a></div>

Any suggestions on how can I hide that element?

Upvotes: 3

Views: 1887

Answers (6)

Albin N
Albin N

Reputation: 1401

I think you'll have to assign an ID to it, and if you can't, why not?

Here's code for hiding it anyways:

JSfiddle-example

Code for hiding with id, without id, and from what your link content is:

http://jsfiddle.net/9eLAJ/3/

Upvotes: 1

Ray Lu
Ray Lu

Reputation: 26658

try

$("a[href='http://bizmate.in']",  $("#container")).closest('div').hide();

Assume in the parent elements of given html, you can find one with id="container", this will ensure the right is found with that container rather than else where since a link like that is pretty common.

Upvotes: 1

nbrooks
nbrooks

Reputation: 18233

Firstly, you really should not put all of those styles inline. It clutters your html, and is poor design since you are mixing styling and layout. It would be better to take it out, use css selectors and wrap it in <style></style> tags; to that end you should also add a class to the <div> to make these selections easier to carry out and more maintainable.

That being said, the following function using .filter() will do what you want...

$("div").filter( function() { 
    return $(this).find("a[href^='http://bizmate.in']").length > 0;
}).hide();

Upvotes: 2

techfoobar
techfoobar

Reputation: 66663

$('div a[href="http://bizmate.in"]').parent().hide(); should work.

Demo: http://jsfiddle.net/C4pYy/

Upvotes: 2

tsergium
tsergium

Reputation: 1176

You can try this

$('div[style*=background: #ebebeb; [...]').hide();

Upvotes: 2

mbinette
mbinette

Reputation: 5094

Why not add an id and then use $('div#myId').hide() ?

<div id="myId" style="background: #ebebeb; [...]">[...]</div>

Upvotes: 1

Related Questions