I have a simple <a> tag that is getting hidden from some JS. (display:none)
I have looked into the page source and I can see it is not hidden, however the inspector shows it as display:none ( inline style )
No result finding out the class/id in JS code in order to isolate the part of the code that is hiding the <a>.
Is there a tool or fixed procedure that can help me to debug this?
Chrome lets you break code when an attribute on an element is changed.
Open the developer tools using F12, and select the "Elements" tab. Find the element that gets hidden. Right click on it, "Break on", "Attributes Modification".
Refresh the page, keeping Developer Tools open.
If the element is being hidden using JavaScript, you'll break at that point.
Otherwise, it's done via CSS. If this is the case, using the "Elements" tab again, select the element you're interested in and look at the "Styles" applied to it in the right hand column. Chrome will show which styles are applied by which definition in which stylesheet. It should then be trivial to find the one hiding the element.
First of all, look if it is hidden from inline style or by a css class.
Then, if is by a css class, search in all your project for that class (you should find a javascript function that adds this class to the element).
If is hidden by inline style property, look inside your project for any .style.display = property.
If you are using jquery try like this:
// Search by class
.addClass(".hiddenClass
// Search by css
.hide(), or $(".elementSelector").hide()
Firstly make sure that it is indeed javascript that hides your element, as it could easily be css. The easiest first step is to check the element and see if by any chance its default css is hiding it.
Second. Is your js code in one file or do you import multiple js files in your page?
If you have multiple js files you could try.
Import 1 file
then use javascript to Show your element
then import the rest of the files.
If the code that hides your element is located in the first file then your element will be visible (because you made it visible after hiding it first)
if the element is not visible it means that the hiding takes place in a subsequent file.
Move your javascript code showing the element after the second import and so on...
Last but not least make sure your code does not import external css files as well.
I recommend using Chrome Dev Tools for any javascript debugging you do.
Related
[![This image shows html code ][1]][1]
my java script code to locate element in protractor is below :
element(by.css("insight-top-bar insight-predefined-charts-container button div")).click();
you might want to add some dots to your locator, for the ones that might belong to a class
element(by.css('.insight-top-bar.insight-predefined-charts-container button div'))
I am looking at a form that has a captcha. The CSS being applied has made it all whacky looking. I'm about to diagnose the issue, and I'm looking at the styles being applied in my Google chrome developer window. For each individual rule, there is light grey text in the top right of the box that says where the code came from. The one rule I'm interested in indicates it came from <style></style>, which I assume is an inline style rule. Clicking on the source, it takes me to the <style> element that is defined and sure enough the rules are there. These rules don't exist in the source file, so I'm pretty sure the element is appended through javascript. When I hit ctrl + u to view the source code, the <style> element is not there.
How can I see an element that exists in the developer window without it existing in the view source code?
Elements created by JavaScript are not visible in source code, that is because they are created dynamicaly, and when you use "view page source" then you get source code of page returned by server without executing JavaScript.
I'm wondering of there is any way to find out where an inline CSS style came from. As you can see in the picture below, I have an element with an inline style that was generated using JavaScript. Sometimes my code seems to break and put the width to 0px, rendering the div invisible.
I've looked through all the JS files, but can't seem to find the error.
Is there a way to find the right file and line, just like dev tools does for css files?
Since you are using Chrome:
Right click on the element in the page and Inspect Element
Right click on the DOM inspector view of the element and Break on… → Attributes Modifications
When the inline style of the element is modified with JS, the debugger will trigger as if it had hit a breakpoint.
This will show you the relevant line of JS and give you a stack so you can figure out where that line was called from.
You can use chrome debugger/ firefox to inspect the element's style and its hierarchy.
Also if you don't want a style assigned by you to be overridden, you can use !important:
#element{
css-property:value !important;
}
I am using a JS library that creates dialogs, but it's core code is very big and complex. The dialogs created have a CSS attribute z-index: 2, whereas I want them to use a larger number. The issue is that this CSS is set directly on the dialog's DIV wrapper during the JS library's runtime (so I can't overwrite them with an external CSS file due to rule preceedence).
I was wondering if there is a way in Chrome Developer Tools or in Firebug to setup a breakpoint for whenever a given, dynamically created element's z-index property is changed, given that I know what id="" and class="" it will be assigned? Basically, the breakpoint should be right before that z-index is set, so I can know where the number 2 comes from in the above example.
In the Firebug HTML tab, right-click on an element and select "Break on attribute change"
I need to know how to use JavaScript to find out from which file a particular CSS class is getting applied to a HTML element.
I am developing a web application where user can change the CSS property of particular element, just like we can change it in Firebug.
Edit: I need the JavaScript code of Firebug which shows CSS in right pane in HTML tab with link to files which has that class.
The window.getComputedStyle method returns a CSSStyleDeclaration. Look at the parentRule property of that to get to the cssRule, that has a parentStyleSheet property which should give you the information you need.
The Firebug Lite code might be a less confusing place to look than the full extension to get an idea of how it's all supposed to fit together.